From 624167331a8fd049f2bf589865f7dcea19dd535e Mon Sep 17 00:00:00 2001 From: Anton Tayanovskyy Date: Fri, 23 Feb 2024 15:05:27 -0500 Subject: [PATCH] Revert "Make sure no nil lists are passed to TF (#1688)" This reverts commit 3425c55fb26a85e5e0de92386a5bdba822768752. --- pkg/tests/regress_aws_1423_test.go | 14 +--- pkg/tfbridge/provider_test.go | 6 +- pkg/tfbridge/schema.go | 12 ---- pkg/tfbridge/schema_test.go | 109 ----------------------------- 4 files changed, 4 insertions(+), 137 deletions(-) diff --git a/pkg/tests/regress_aws_1423_test.go b/pkg/tests/regress_aws_1423_test.go index deeb414f9..ce3ee3389 100644 --- a/pkg/tests/regress_aws_1423_test.go +++ b/pkg/tests/regress_aws_1423_test.go @@ -27,7 +27,6 @@ import ( ) func TestRegressAws1423(t *testing.T) { - t.Skip("Refresh is dirty on this resource see https://github.com/pulumi/pulumi-aws/issues/3361.") ctx := context.Background() resource := webaclschema.ResourceWebACL() @@ -39,16 +38,7 @@ func TestRegressAws1423(t *testing.T) { }, } - p := shimv2.NewProvider(tfProvider, shimv2.WithDiffStrategy(shimv2.PlanState), - shimv2.WithPlanResourceChange(func(s string) bool { - switch s { - case "aws_wafv2_web_acl": - return true - default: - return false - } - }), - ) + p := shimv2.NewProvider(tfProvider, shimv2.WithDiffStrategy(shimv2.PlanState)) info := tfbridge.ProviderInfo{ P: p, @@ -73,6 +63,8 @@ func TestRegressAws1423(t *testing.T) { []byte{}, /* pulumiSchema */ ) + shimv2.SetInstanceStateStrategy(p.ResourcesMap().Get("aws_wafv2_web_acl"), shimv2.CtyInstanceState) + testCase1 := ` { "method": "/pulumirpc.ResourceProvider/Create", diff --git a/pkg/tfbridge/provider_test.go b/pkg/tfbridge/provider_test.go index be37a6825..d04fa600a 100644 --- a/pkg/tfbridge/provider_test.go +++ b/pkg/tfbridge/provider_test.go @@ -757,8 +757,7 @@ func TestCheckCallback(t *testing.T) { "response": { "inputs": { "__defaults": [], - "arrayPropertyValues": ["global"], - "nestedResources": null + "arrayPropertyValues": ["global"] } } } @@ -1045,7 +1044,6 @@ func TestCheck(t *testing.T) { "inputs": { "__defaults": ["stringPropertyValue"], "arrayPropertyValues": [], - "nestedResources": null, "stringPropertyValue": "oldString!" } } @@ -1068,7 +1066,6 @@ func TestCheck(t *testing.T) { "response": { "inputs": { "__defaults": [], - "nestedResources": null, "arrayPropertyValues": [] } } @@ -1113,7 +1110,6 @@ func TestCheck(t *testing.T) { "inputs": { "__defaults": [], "arrayPropertyValues": [], - "nestedResources": null, "stringPropertyValue": { "4dabf18193072939515e22adb298388d": "1b47061264138c4ac30d75fd1eb44270", "value": "newString" diff --git a/pkg/tfbridge/schema.go b/pkg/tfbridge/schema.go index e53fa6487..e358c9b64 100644 --- a/pkg/tfbridge/schema.go +++ b/pkg/tfbridge/schema.go @@ -655,18 +655,6 @@ func (ctx *conversionContext) makeObjectTerraformInputs( return nil, err } - if tfs != nil { - // Iterate over the TF schema and add an empty array for each nil MaxItemsOne property. - tfs.Range(func(key string, value shim.Schema) bool { - // First do a lookup of the name/info. - _, tfi, psi := getInfoFromTerraformName(key, tfs, ps, rawNames) - if IsMaxItemsOne(tfi, psi) && result[key] == nil { - result[key] = []interface{}{} - } - return true - }) - } - if glog.V(5) { for k, v := range result { glog.V(5).Infof("Terraform input %v = %#v", k, v) diff --git a/pkg/tfbridge/schema_test.go b/pkg/tfbridge/schema_test.go index 95eb6357e..7c8ec6a30 100644 --- a/pkg/tfbridge/schema_test.go +++ b/pkg/tfbridge/schema_test.go @@ -411,115 +411,6 @@ func TestMakeTerraformInputMixedMaxItemsOne(t *testing.T) { } } -func TestMaxItemsOneEmptyOldState(t *testing.T) { - t.Run("empty-olds", func(t *testing.T) { - typeString := (&schema.Schema{ - Type: shim.TypeString, - }).Shim() - - resSchema := &schema.Schema{ - Type: shim.TypeList, - MaxItems: 1, - Elem: (&schema.Schema{ - Type: shim.TypeList, - Elem: typeString, - }).Shim(), - } - - olds := resource.PropertyMap{} - news := resource.PropertyMap{ - "__defaults": resource.NewArrayProperty( - []resource.PropertyValue{ - resource.NewStringProperty("other"), - }, - ), - } - tfs := schema.SchemaMap{"element": resSchema.Shim()} - result, _, err := makeTerraformInputs( - olds, news, tfs, nil /* ps */) - require.NoError(t, err) - assert.Equal(t, map[string]interface{}{ - "element": []interface{}{}, - }, result) - }) - - t.Run("non-empty-olds", func(t *testing.T) { - typeString := (&schema.Schema{ - Type: shim.TypeString, - }).Shim() - - resSchema := &schema.Schema{ - Type: shim.TypeList, - MaxItems: 1, - Elem: (&schema.Schema{ - Type: shim.TypeList, - Elem: typeString, - }).Shim(), - } - - olds := resource.PropertyMap{ - "element": resource.NewStringProperty("el"), - "__defaults": resource.NewArrayProperty( - []resource.PropertyValue{ - resource.NewStringProperty("other"), - }, - ), - } - news := resource.PropertyMap{ - "__defaults": resource.NewArrayProperty( - []resource.PropertyValue{ - resource.NewStringProperty("other"), - }, - ), - } - tfs := schema.SchemaMap{"element": resSchema.Shim()} - result, _, err := makeTerraformInputs( - olds, news, tfs, nil /* ps */) - require.NoError(t, err) - assert.Equal(t, map[string]interface{}{ - "element": []interface{}{}, - }, result) - }) - - t.Run("non-missing-news", func(t *testing.T) { - typeString := (&schema.Schema{ - Type: shim.TypeString, - }).Shim() - - resSchema := &schema.Schema{ - Type: shim.TypeList, - MaxItems: 1, - Elem: (&schema.Schema{ - Type: shim.TypeList, - Elem: typeString, - }).Shim(), - } - - olds := resource.PropertyMap{ - "__defaults": resource.NewArrayProperty( - []resource.PropertyValue{ - resource.NewStringProperty("other"), - }, - ), - } - news := resource.PropertyMap{ - "element": resource.NewStringProperty("el"), - "__defaults": resource.NewArrayProperty( - []resource.PropertyValue{ - resource.NewStringProperty("other"), - }, - ), - } - tfs := schema.SchemaMap{"element": resSchema.Shim()} - result, _, err := makeTerraformInputs( - olds, news, tfs, nil /* ps */) - require.NoError(t, err) - assert.Equal(t, map[string]interface{}{ - "element": []interface{}{"el"}, - }, result) - }) -} - type MyString string // TestTerraformOutputsWithSecretsSupported verifies that we translate Terraform outputs into Pulumi outputs and