Skip to content

Commit

Permalink
Revert "Make sure no nil lists are passed to TF" (#1697)
Browse files Browse the repository at this point in the history
Reverts #1688
  • Loading branch information
guineveresaenger committed Feb 23, 2024
2 parents afedecf + 6241673 commit 759f13a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 137 deletions.
14 changes: 3 additions & 11 deletions pkg/tests/regress_aws_1423_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions pkg/tfbridge/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,7 @@ func TestCheckCallback(t *testing.T) {
"response": {
"inputs": {
"__defaults": [],
"arrayPropertyValues": ["global"],
"nestedResources": null
"arrayPropertyValues": ["global"]
}
}
}
Expand Down Expand Up @@ -1045,7 +1044,6 @@ func TestCheck(t *testing.T) {
"inputs": {
"__defaults": ["stringPropertyValue"],
"arrayPropertyValues": [],
"nestedResources": null,
"stringPropertyValue": "oldString!"
}
}
Expand All @@ -1068,7 +1066,6 @@ func TestCheck(t *testing.T) {
"response": {
"inputs": {
"__defaults": [],
"nestedResources": null,
"arrayPropertyValues": []
}
}
Expand Down Expand Up @@ -1113,7 +1110,6 @@ func TestCheck(t *testing.T) {
"inputs": {
"__defaults": [],
"arrayPropertyValues": [],
"nestedResources": null,
"stringPropertyValue": {
"4dabf18193072939515e22adb298388d": "1b47061264138c4ac30d75fd1eb44270",
"value": "newString"
Expand Down
12 changes: 0 additions & 12 deletions pkg/tfbridge/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
109 changes: 0 additions & 109 deletions pkg/tfbridge/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 759f13a

Please sign in to comment.