diff --git a/pkg/internal/tests/cross-tests/puwrite_test.go b/pkg/internal/tests/cross-tests/puwrite_test.go index dc0959c9a..28afdca76 100644 --- a/pkg/internal/tests/cross-tests/puwrite_test.go +++ b/pkg/internal/tests/cross-tests/puwrite_test.go @@ -120,9 +120,7 @@ runtime: yaml }, }, } - shimProvider := shimv2.NewProvider(tfp, shimv2.WithPlanResourceChange( - func(tfResourceType string) bool { return true }, - )) + shimProvider := shimv2.NewProvider(tfp) schema := shimProvider.ResourcesMap().Get(rtype).Schema() out, err := generateYaml(t, rtoken, crosstestsimpl.InferPulumiValue(t, schema, nil, coalesceInputs(t, tc.schema, tc.tfConfig))) diff --git a/pkg/internal/tests/cross-tests/upgrade_state_check.go b/pkg/internal/tests/cross-tests/upgrade_state_check.go index de7c59a6f..4a7bf1bed 100644 --- a/pkg/internal/tests/cross-tests/upgrade_state_check.go +++ b/pkg/internal/tests/cross-tests/upgrade_state_check.go @@ -41,8 +41,6 @@ type upgradeStateTestCase struct { Config2 any ExpectEqual bool ObjectType *tftypes.Object - - DisablePlanResourceChange bool } func getVersionInState(t T, stack apitype.UntypedDeployment) int { @@ -71,11 +69,8 @@ func getVersionInState(t T, stack apitype.UntypedDeployment) int { return int(schemaVersion) } -func runPulumiUpgrade(t T, res1, res2 *schema.Resource, config1, config2 cty.Value, disablePlanResourceChange bool) (int, int) { +func runPulumiUpgrade(t T, res1, res2 *schema.Resource, config1, config2 cty.Value) (int, int) { opts := []pulcheck.BridgedProviderOpt{} - if disablePlanResourceChange { - opts = append(opts, pulcheck.DisablePlanResourceChange()) - } tfp1 := &schema.Provider{ResourcesMap: map[string]*schema.Resource{defRtype: res1}} prov1 := pulcheck.BridgedProvider(t, defProviderShortName, tfp1, opts...) @@ -160,7 +155,7 @@ func runUpgradeStateInputCheck(t T, tc upgradeStateTestCase) { tfd2 := newTFResDriver(t, tfwd, defProviderShortName, defRtype, &upgradeRes) _ = tfd2.writePlanApply(t, tc.Resource.Schema, defRtype, "example", config2, lifecycleArgs{}) - schemaVersion1, schemaVersion2 := runPulumiUpgrade(t, tc.Resource, &upgradeRes, config1, config2, tc.DisablePlanResourceChange) + schemaVersion1, schemaVersion2 := runPulumiUpgrade(t, tc.Resource, &upgradeRes, config1, config2) if tc.ExpectEqual { assert.Equal(t, schemaVersion1, tc.Resource.SchemaVersion) diff --git a/pkg/internal/tests/cross-tests/upgrade_state_cross_test.go b/pkg/internal/tests/cross-tests/upgrade_state_cross_test.go index 9adeecb67..cc2367efc 100644 --- a/pkg/internal/tests/cross-tests/upgrade_state_cross_test.go +++ b/pkg/internal/tests/cross-tests/upgrade_state_cross_test.go @@ -1,7 +1,6 @@ package crosstests import ( - "fmt" "testing" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -28,28 +27,22 @@ func TestUpgradeInputsStringBasic(t *testing.T) { "f0": tftypes.NewValue(tftypes.String, val), }) } - for _, PRC := range []bool{true, false} { - t.Run(fmt.Sprintf("PRC=%v", PRC), func(t *testing.T) { - t.Run("same", func(t *testing.T) { - runUpgradeStateInputCheck(t, upgradeStateTestCase{ - Resource: res, - Config1: configVal("val"), - Config2: configVal("val"), - DisablePlanResourceChange: !PRC, - ExpectEqual: true, - }) - }) + t.Run("same", func(t *testing.T) { + runUpgradeStateInputCheck(t, upgradeStateTestCase{ + Resource: res, + Config1: configVal("val"), + Config2: configVal("val"), + ExpectEqual: true, + }) + }) - t.Run("different", func(t *testing.T) { - runUpgradeStateInputCheck(t, upgradeStateTestCase{ - Resource: res, - Config1: configVal("val1"), - Config2: configVal("val2"), - DisablePlanResourceChange: !PRC, - }) - }) + t.Run("different", func(t *testing.T) { + runUpgradeStateInputCheck(t, upgradeStateTestCase{ + Resource: res, + Config1: configVal("val1"), + Config2: configVal("val2"), }) - } + }) } func TestUpgradeInputsStringBasicNonZeroVersion(t *testing.T) { @@ -73,28 +66,22 @@ func TestUpgradeInputsStringBasicNonZeroVersion(t *testing.T) { "f0": tftypes.NewValue(tftypes.String, val), }) } - for _, PRC := range []bool{true, false} { - t.Run(fmt.Sprintf("PRC=%v", PRC), func(t *testing.T) { - t.Run("same", func(t *testing.T) { - runUpgradeStateInputCheck(t, upgradeStateTestCase{ - Resource: res, - Config1: configVal("val"), - Config2: configVal("val"), - DisablePlanResourceChange: !PRC, - ExpectEqual: true, - }) - }) + t.Run("same", func(t *testing.T) { + runUpgradeStateInputCheck(t, upgradeStateTestCase{ + Resource: res, + Config1: configVal("val"), + Config2: configVal("val"), + ExpectEqual: true, + }) + }) - t.Run("different", func(t *testing.T) { - runUpgradeStateInputCheck(t, upgradeStateTestCase{ - Resource: res, - Config1: configVal("val1"), - Config2: configVal("val2"), - DisablePlanResourceChange: !PRC, - }) - }) + t.Run("different", func(t *testing.T) { + runUpgradeStateInputCheck(t, upgradeStateTestCase{ + Resource: res, + Config1: configVal("val1"), + Config2: configVal("val2"), }) - } + }) } func TestUpgradeInputsObjectBasic(t *testing.T) { @@ -140,26 +127,20 @@ func TestUpgradeInputsObjectBasic(t *testing.T) { }, ) } - for _, PRC := range []bool{true, false} { - t.Run(fmt.Sprintf("PRC=%v", PRC), func(t *testing.T) { - t.Run("same", func(t *testing.T) { - runUpgradeStateInputCheck(t, upgradeStateTestCase{ - Resource: res, - Config1: configVal("val"), - Config2: configVal("val"), - DisablePlanResourceChange: !PRC, - ExpectEqual: true, - }) - }) + t.Run("same", func(t *testing.T) { + runUpgradeStateInputCheck(t, upgradeStateTestCase{ + Resource: res, + Config1: configVal("val"), + Config2: configVal("val"), + ExpectEqual: true, + }) + }) - t.Run("different", func(t *testing.T) { - runUpgradeStateInputCheck(t, upgradeStateTestCase{ - Resource: res, - Config1: configVal("val1"), - Config2: configVal("val2"), - DisablePlanResourceChange: !PRC, - }) - }) + t.Run("different", func(t *testing.T) { + runUpgradeStateInputCheck(t, upgradeStateTestCase{ + Resource: res, + Config1: configVal("val1"), + Config2: configVal("val2"), }) - } + }) } diff --git a/pkg/tests/import_test.go b/pkg/tests/import_test.go index e1d90008e..3f0c5e984 100644 --- a/pkg/tests/import_test.go +++ b/pkg/tests/import_test.go @@ -411,7 +411,7 @@ func TestFailedValidatorOnReadHandling(t *testing.T) { }, } tfp := &schema.Provider{ResourcesMap: resMap} - bridgedProvider := pulcheck.BridgedProvider(t, "prov", tfp, pulcheck.DisablePlanResourceChange()) + bridgedProvider := pulcheck.BridgedProvider(t, "prov", tfp) program := ` name: test runtime: yaml diff --git a/pkg/tests/pulcheck/pulcheck.go b/pkg/tests/pulcheck/pulcheck.go index 685ea6f68..38b90ad9f 100644 --- a/pkg/tests/pulcheck/pulcheck.go +++ b/pkg/tests/pulcheck/pulcheck.go @@ -127,22 +127,14 @@ type T interface { } type bridgedProviderOpts struct { - DisablePlanResourceChange bool - StateEdit shimv2.PlanStateEditFunc - resourceInfo map[string]*info.Resource - configInfo map[string]*info.Schema + StateEdit shimv2.PlanStateEditFunc + resourceInfo map[string]*info.Resource + configInfo map[string]*info.Schema } // BridgedProviderOpts type BridgedProviderOpt func(*bridgedProviderOpts) -// WithPlanResourceChange -func DisablePlanResourceChange() BridgedProviderOpt { - return func(o *bridgedProviderOpts) { - o.DisablePlanResourceChange = true - } -} - func WithStateEdit(f shimv2.PlanStateEditFunc) BridgedProviderOpt { return func(o *bridgedProviderOpts) { o.StateEdit = f @@ -175,9 +167,6 @@ func BridgedProvider(t T, providerName string, tfp *schema.Provider, opts ...Bri EnsureProviderValid(t, tfp) shimProvider := shimv2.NewProvider(tfp, - shimv2.WithPlanResourceChange( - func(tfResourceType string) bool { return !options.DisablePlanResourceChange }, - ), shimv2.WithPlanStateEdit(options.StateEdit), ) diff --git a/pkg/tests/refresh_test.go b/pkg/tests/refresh_test.go index e559aca5a..78f3b6d9f 100644 --- a/pkg/tests/refresh_test.go +++ b/pkg/tests/refresh_test.go @@ -18,7 +18,6 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { t.Parallel() for _, tc := range []struct { name string - planResourceChange bool schemaType schema.ValueType cloudVal interface{} programVal string @@ -32,44 +31,22 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { }{ { name: "map null with planResourceChange", - planResourceChange: true, schemaType: schema.TypeMap, cloudVal: map[string]interface{}{}, programVal: "null", expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "map null without planResourceChange", - planResourceChange: false, - schemaType: schema.TypeMap, - cloudVal: map[string]interface{}{}, - programVal: "null", - // Note the difference in expected output between top level and nested properties - expectedOutputTopLevel: nil, - expectedOutputNested: map[string]interface{}{}, - }, { name: "map null with planResourceChange with nil cloud value", - planResourceChange: true, schemaType: schema.TypeMap, cloudVal: nil, programVal: "null", expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "map null without planResourceChange with nil cloud value", - planResourceChange: false, - schemaType: schema.TypeMap, - cloudVal: nil, - programVal: "null", - expectedOutputTopLevel: nil, - expectedOutputNested: map[string]interface{}{}, - }, { name: "map null with planResourceChange with cloud override", - planResourceChange: true, schemaType: schema.TypeMap, cloudVal: map[string]interface{}{}, programVal: "null", @@ -77,19 +54,8 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "map null without planResourceChange with cloud override", - planResourceChange: false, - schemaType: schema.TypeMap, - cloudVal: map[string]interface{}{}, - programVal: "null", - createCloudValOverride: true, - expectedOutputTopLevel: map[string]interface{}{}, - expectedOutputNested: map[string]interface{}{}, - }, { name: "map null with planResourceChange with nil cloud value and cloud override", - planResourceChange: true, schemaType: schema.TypeMap, cloudVal: nil, programVal: "null", @@ -97,38 +63,16 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "map null without planResourceChange with nil cloud value and cloud override", - planResourceChange: false, - schemaType: schema.TypeMap, - cloudVal: nil, - programVal: "null", - createCloudValOverride: true, - expectedOutputTopLevel: map[string]interface{}{}, - expectedOutputNested: map[string]interface{}{}, - }, { name: "map empty with planResourceChange", - planResourceChange: true, schemaType: schema.TypeMap, cloudVal: map[string]interface{}{}, programVal: "{}", expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "map empty without planResourceChange", - planResourceChange: false, - schemaType: schema.TypeMap, - cloudVal: map[string]interface{}{}, - programVal: "{}", - // Note the difference in expected output between top level and nested properties - expectedOutputTopLevel: nil, - expectedOutputNested: map[string]interface{}{}, - }, { name: "map empty with planResourceChange with cloud override", - planResourceChange: true, schemaType: schema.TypeMap, cloudVal: map[string]interface{}{}, programVal: "{}", @@ -136,28 +80,8 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "map empty without planResourceChange with cloud override", - planResourceChange: false, - schemaType: schema.TypeMap, - cloudVal: map[string]interface{}{}, - programVal: "{}", - createCloudValOverride: true, - expectedOutputTopLevel: map[string]interface{}{}, - expectedOutputNested: map[string]interface{}{}, - }, { name: "map nonempty with planResourceChange", - planResourceChange: true, - schemaType: schema.TypeMap, - cloudVal: map[string]interface{}{"val": "test"}, - programVal: `{"val": "test"}`, - expectedOutputTopLevel: map[string]interface{}{"val": "test"}, - expectedOutputNested: map[string]interface{}{"val": "test"}, - }, - { - name: "map nonempty without planResourceChange", - planResourceChange: false, schemaType: schema.TypeMap, cloudVal: map[string]interface{}{"val": "test"}, programVal: `{"val": "test"}`, @@ -166,17 +90,6 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { }, { name: "map nonempty with planResourceChange with cloud override", - planResourceChange: true, - schemaType: schema.TypeMap, - cloudVal: map[string]interface{}{"val": "test"}, - programVal: `{"val": "test"}`, - createCloudValOverride: true, - expectedOutputTopLevel: map[string]interface{}{"val": "test"}, - expectedOutputNested: map[string]interface{}{"val": "test"}, - }, - { - name: "map nonempty without planResourceChange with cloud override", - planResourceChange: false, schemaType: schema.TypeMap, cloudVal: map[string]interface{}{"val": "test"}, programVal: `{"val": "test"}`, @@ -186,45 +99,22 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { }, { name: "list null with planResourceChange", - planResourceChange: true, schemaType: schema.TypeList, cloudVal: []interface{}{}, programVal: "null", expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "list null without planResourceChange", - planResourceChange: false, - schemaType: schema.TypeList, - cloudVal: []interface{}{}, - programVal: "null", - // Note the difference in expected output between top level and nested properties - expectedOutputTopLevel: nil, - expectedOutputNested: []interface{}{}, - }, { name: "list null with planResourceChange with nil cloud value", - planResourceChange: true, schemaType: schema.TypeList, cloudVal: nil, programVal: "null", expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "list null without planResourceChange with nil cloud value", - planResourceChange: false, - schemaType: schema.TypeList, - cloudVal: nil, - programVal: "null", - // Note the difference in expected output between top level and nested properties - expectedOutputTopLevel: nil, - expectedOutputNested: []interface{}{}, - }, { name: "list null with planResourceChange with cloud override", - planResourceChange: true, schemaType: schema.TypeList, cloudVal: []interface{}{}, programVal: "null", @@ -232,19 +122,8 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "list null without planResourceChange with cloud override", - planResourceChange: false, - schemaType: schema.TypeList, - cloudVal: []interface{}{}, - programVal: "null", - createCloudValOverride: true, - expectedOutputTopLevel: []interface{}{}, - expectedOutputNested: []interface{}{}, - }, { name: "list null with planResourceChange with nil cloud value and cloud override", - planResourceChange: true, schemaType: schema.TypeList, cloudVal: nil, programVal: "null", @@ -252,48 +131,16 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "list null without planResourceChange with nil cloud value and cloud override", - planResourceChange: false, - schemaType: schema.TypeList, - cloudVal: nil, - programVal: "null", - createCloudValOverride: true, - expectedOutputTopLevel: []interface{}{}, - expectedOutputNested: []interface{}{}, - }, { name: "list empty with planResourceChange", - planResourceChange: true, schemaType: schema.TypeList, cloudVal: []string{}, programVal: "[]", expectedOutputTopLevel: []interface{}{}, expectedOutputNested: []interface{}{}, }, - { - name: "list empty without planResourceChange", - planResourceChange: false, - schemaType: schema.TypeList, - cloudVal: []string{}, - programVal: "[]", - // Note the difference in expected output between top level and nested properties - expectedOutputTopLevel: nil, - expectedOutputNested: []interface{}{}, - }, { name: "list empty with planResourceChange with cloud override", - planResourceChange: true, - schemaType: schema.TypeList, - cloudVal: []string{}, - programVal: "[]", - createCloudValOverride: true, - expectedOutputTopLevel: []interface{}{}, - expectedOutputNested: []interface{}{}, - }, - { - name: "list empty without planResourceChange with cloud override", - planResourceChange: false, schemaType: schema.TypeList, cloudVal: []string{}, programVal: "[]", @@ -303,16 +150,6 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { }, { name: "list nonempty with planResourceChange", - planResourceChange: true, - schemaType: schema.TypeList, - cloudVal: []interface{}{"val"}, - programVal: `["val"]`, - expectedOutputTopLevel: []interface{}{"val"}, - expectedOutputNested: []interface{}{"val"}, - }, - { - name: "list nonempty without planResourceChange", - planResourceChange: false, schemaType: schema.TypeList, cloudVal: []interface{}{"val"}, programVal: `["val"]`, @@ -321,17 +158,6 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { }, { name: "list nonempty with planResourceChange with cloud override", - planResourceChange: true, - schemaType: schema.TypeList, - cloudVal: []interface{}{"val"}, - programVal: `["val"]`, - createCloudValOverride: true, - expectedOutputTopLevel: []interface{}{"val"}, - expectedOutputNested: []interface{}{"val"}, - }, - { - name: "list nonempty without planResourceChange with cloud override", - planResourceChange: false, schemaType: schema.TypeList, cloudVal: []interface{}{"val"}, programVal: `["val"]`, @@ -341,44 +167,22 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { }, { name: "set null with planResourceChange", - planResourceChange: true, schemaType: schema.TypeSet, cloudVal: []interface{}{}, programVal: "null", expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "set null without planResourceChange", - planResourceChange: false, - schemaType: schema.TypeSet, - cloudVal: []interface{}{}, - programVal: "null", - // Note the difference in expected output between top level and nested properties - expectedOutputTopLevel: nil, - expectedOutputNested: []interface{}{}, - }, { name: "set null with planResourceChange with nil cloud value", - planResourceChange: true, schemaType: schema.TypeSet, cloudVal: nil, programVal: "null", expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "set null without planResourceChange with nil cloud value", - planResourceChange: false, - schemaType: schema.TypeSet, - cloudVal: nil, - programVal: "null", - expectedOutputTopLevel: nil, - expectedOutputNested: []interface{}{}, - }, { name: "set null with planResourceChange with cloud override", - planResourceChange: true, schemaType: schema.TypeSet, cloudVal: []interface{}{}, programVal: "null", @@ -386,19 +190,8 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "set null without planResourceChange with cloud override", - planResourceChange: false, - schemaType: schema.TypeSet, - cloudVal: []interface{}{}, - programVal: "null", - createCloudValOverride: true, - expectedOutputTopLevel: []interface{}{}, - expectedOutputNested: []interface{}{}, - }, { name: "set null with planResourceChange with nil cloud value and cloud override", - planResourceChange: true, schemaType: schema.TypeSet, cloudVal: nil, programVal: "null", @@ -406,38 +199,16 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "set null without planResourceChange with nil cloud value and cloud override", - planResourceChange: false, - schemaType: schema.TypeSet, - cloudVal: nil, - programVal: "null", - createCloudValOverride: true, - expectedOutputTopLevel: []interface{}{}, - expectedOutputNested: []interface{}{}, - }, { name: "set empty with planResourceChange", - planResourceChange: true, schemaType: schema.TypeSet, cloudVal: []interface{}{}, programVal: "[]", expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "set empty without planResourceChange", - planResourceChange: false, - schemaType: schema.TypeSet, - cloudVal: []interface{}{}, - programVal: "[]", - // Note the difference in expected output between top level and nested properties - expectedOutputTopLevel: nil, - expectedOutputNested: []interface{}{}, - }, { name: "set empty with planResourceChange with cloud override", - planResourceChange: true, schemaType: schema.TypeSet, cloudVal: []interface{}{}, programVal: "[]", @@ -445,16 +216,6 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { expectedOutputTopLevel: nil, expectedOutputNested: nil, }, - { - name: "set empty without planResourceChange with cloud override", - planResourceChange: false, - schemaType: schema.TypeSet, - cloudVal: []interface{}{}, - programVal: "[]", - createCloudValOverride: true, - expectedOutputTopLevel: []interface{}{}, - expectedOutputNested: []interface{}{}, - }, { name: "set nonempty with planResourceChange", schemaType: schema.TypeSet, @@ -463,15 +224,6 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { expectedOutputTopLevel: []interface{}{"val"}, expectedOutputNested: []interface{}{"val"}, }, - { - name: "set nonempty without planResourceChange", - planResourceChange: false, - schemaType: schema.TypeSet, - cloudVal: []interface{}{"val"}, - programVal: `["val"]`, - expectedOutputTopLevel: []interface{}{"val"}, - expectedOutputNested: []interface{}{"val"}, - }, { name: "set nonempty with planResourceChange with cloud override", schemaType: schema.TypeSet, @@ -481,16 +233,6 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { expectedOutputTopLevel: []interface{}{"val"}, expectedOutputNested: []interface{}{"val"}, }, - { - name: "set nonempty without planResourceChange with cloud override", - planResourceChange: false, - schemaType: schema.TypeSet, - cloudVal: []interface{}{"val"}, - programVal: `["val"]`, - createCloudValOverride: true, - expectedOutputTopLevel: []interface{}{"val"}, - expectedOutputNested: []interface{}{"val"}, - }, } { collectionPropPlural := "" pluralized := tc.schemaType == schema.TypeList || tc.schemaType == schema.TypeSet @@ -499,9 +241,6 @@ func TestCollectionsNullEmptyRefreshClean(t *testing.T) { } opts := []pulcheck.BridgedProviderOpt{} - if !tc.planResourceChange { - opts = append(opts, pulcheck.DisablePlanResourceChange()) - } t.Run(tc.name, func(t *testing.T) { t.Run("top level", func(t *testing.T) { diff --git a/pkg/tests/regress_aws_1423_test.go b/pkg/tests/regress_aws_1423_test.go index 9e719a9c8..b128e4266 100644 --- a/pkg/tests/regress_aws_1423_test.go +++ b/pkg/tests/regress_aws_1423_test.go @@ -27,7 +27,7 @@ import ( ) func TestRegressAws1423(t *testing.T) { - t.Parallel() + t.Parallel() ctx := context.Background() resource := webaclschema.ResourceWebACL() @@ -41,9 +41,7 @@ func TestRegressAws1423(t *testing.T) { p := shimv2.NewProvider(tfProvider, shimv2.WithDiffStrategy(shimv2.PlanState), - shimv2.WithPlanResourceChange(func(s string) bool { - return s == "aws_wafv2_web_acl" - })) + ) info := tfbridge.ProviderInfo{ P: p, diff --git a/pkg/tests/schema_pulumi_test.go b/pkg/tests/schema_pulumi_test.go index efc435ade..a634ed95e 100644 --- a/pkg/tests/schema_pulumi_test.go +++ b/pkg/tests/schema_pulumi_test.go @@ -87,23 +87,19 @@ func TestBigIntOverride(t *testing.T) { }, } - runTest := func(t *testing.T, PRC bool) { - tfp := &schema.Provider{ResourcesMap: resMap} - opts := []pulcheck.BridgedProviderOpt{} - if !PRC { - opts = append(opts, pulcheck.DisablePlanResourceChange()) - } - bridgedProvider := pulcheck.BridgedProvider(t, "prov", tfp, opts...) - bridgedProvider.Resources["prov_test"] = &tfbridge.ResourceInfo{ - Tok: "prov:index:Test", - Fields: map[string]*tfbridge.SchemaInfo{ - "managed_zone_id": { - Type: "string", - }, + tfp := &schema.Provider{ResourcesMap: resMap} + opts := []pulcheck.BridgedProviderOpt{} + bridgedProvider := pulcheck.BridgedProvider(t, "prov", tfp, opts...) + bridgedProvider.Resources["prov_test"] = &tfbridge.ResourceInfo{ + Tok: "prov:index:Test", + Fields: map[string]*tfbridge.SchemaInfo{ + "managed_zone_id": { + Type: "string", }, - } + }, + } - program := ` + program := ` name: test runtime: yaml resources: @@ -113,35 +109,26 @@ resources: prop: %s ` - pt := pulcheck.PulCheck(t, bridgedProvider, fmt.Sprintf(program, "val")) - pt.Up(t) - - // Check the state is correct - stack := pt.ExportStack(t) - data, err := stack.Deployment.MarshalJSON() - require.NoError(t, err) - require.Equal(t, fmt.Sprint(bigInt), getZoneFromStack(data)) - - program2 := fmt.Sprintf(program, "val2") - pulumiYamlPath := filepath.Join(pt.CurrentStack().Workspace().WorkDir(), "Pulumi.yaml") - err = os.WriteFile(pulumiYamlPath, []byte(program2), 0o600) - require.NoError(t, err) - - pt.Up(t) - // Check the state is correct - stack = pt.ExportStack(t) - data, err = stack.Deployment.MarshalJSON() - require.NoError(t, err) - require.Equal(t, fmt.Sprint(bigInt), getZoneFromStack(data)) - } - - t.Run("PRC disabled", func(t *testing.T) { - runTest(t, false) - }) - - t.Run("PRC enabled", func(t *testing.T) { - runTest(t, true) - }) + pt := pulcheck.PulCheck(t, bridgedProvider, fmt.Sprintf(program, "val")) + pt.Up(t) + + // Check the state is correct + stack := pt.ExportStack(t) + data, err := stack.Deployment.MarshalJSON() + require.NoError(t, err) + require.Equal(t, fmt.Sprint(bigInt), getZoneFromStack(data)) + + program2 := fmt.Sprintf(program, "val2") + pulumiYamlPath := filepath.Join(pt.CurrentStack().Workspace().WorkDir(), "Pulumi.yaml") + err = os.WriteFile(pulumiYamlPath, []byte(program2), 0o600) + require.NoError(t, err) + + pt.Up(t) + // Check the state is correct + stack = pt.ExportStack(t) + data, err = stack.Deployment.MarshalJSON() + require.NoError(t, err) + require.Equal(t, fmt.Sprint(bigInt), getZoneFromStack(data)) } func TestMakeTerraformResultNilVsEmptyMap(t *testing.T) { diff --git a/pkg/tfbridge/provider_test.go b/pkg/tfbridge/provider_test.go index 80c154666..0857a07fa 100644 --- a/pkg/tfbridge/provider_test.go +++ b/pkg/tfbridge/provider_test.go @@ -526,12 +526,6 @@ func TestIgnoreChangesV2(t *testing.T) { testIgnoreChangesV2(t, shimv2.NewProvider(testTFProviderV2)) } -func TestIgnoreChangesV2WithPlanResourceChange(t *testing.T) { - t.Parallel() - opt := shimv2.WithPlanResourceChange(func(string) bool { return true }) - testIgnoreChangesV2(t, shimv2.NewProvider(testTFProviderV2, opt)) -} - func testIgnoreChangesV2(t *testing.T, prov shim.Provider) { provider := &Provider{ tf: prov, @@ -3286,17 +3280,9 @@ func TestPreConfigureCallbackEmitsFailures(t *testing.T) { func TestImport(t *testing.T) { t.Parallel() - t.Run("sdkv2", func(t *testing.T) { - testImport(t, func(p *schema.Provider) shim.Provider { - return shimv2.NewProvider(p) - }) - }) - t.Run("sdkv2/planResourceChange", func(t *testing.T) { - testImport(t, func(p *schema.Provider) shim.Provider { - return shimv2.NewProvider(p, shimv2.WithPlanResourceChange(func(s string) bool { - return true - })) - }) + + testImport(t, func(p *schema.Provider) shim.Provider { + return shimv2.NewProvider(p) }) } @@ -3383,17 +3369,8 @@ func testImport(t *testing.T, newProvider func(*schema.Provider) shim.Provider) func TestRefresh(t *testing.T) { t.Parallel() - t.Run("sdkv2", func(t *testing.T) { - testRefresh(t, func(p *schema.Provider) shim.Provider { - return shimv2.NewProvider(p) - }) - }) - t.Run("sdkv2/planResourceChange", func(t *testing.T) { - testRefresh(t, func(p *schema.Provider) shim.Provider { - return shimv2.NewProvider(p, shimv2.WithPlanResourceChange(func(s string) bool { - return true - })) - }) + testRefresh(t, func(p *schema.Provider) shim.Provider { + return shimv2.NewProvider(p) }) } @@ -3531,17 +3508,9 @@ func testRefresh(t *testing.T, newProvider func(*schema.Provider) shim.Provider) func TestDestroy(t *testing.T) { t.Parallel() - t.Run("sdkv2", func(t *testing.T) { - testDestroy(t, func(p *schema.Provider) shim.Provider { - return shimv2.NewProvider(p) - }) - }) - t.Run("sdkv2/planResourceChange", func(t *testing.T) { - testDestroy(t, func(p *schema.Provider) shim.Provider { - return shimv2.NewProvider(p, shimv2.WithPlanResourceChange(func(s string) bool { - return true - })) - }) + + testDestroy(t, func(p *schema.Provider) shim.Provider { + return shimv2.NewProvider(p) }) } @@ -4177,10 +4146,7 @@ func TestCustomTimeouts(t *testing.T) { }, } - shimmedProvider := shimv2.NewProvider(upstreamProvider, - shimv2.WithPlanResourceChange(func(tfResourceType string) bool { - return true - })) + shimmedProvider := shimv2.NewProvider(upstreamProvider) bridgedProvider := &Provider{ tf: shimmedProvider, @@ -4368,7 +4334,7 @@ func TestProviderMetaPlanResourceChangeNoError(t *testing.T) { } p.SetMeta(otherMetaType{val: "foo"}) - shimProv := shimv2.NewProvider(p, shimv2.WithPlanResourceChange(func(string) bool { return true })) + shimProv := shimv2.NewProvider(p) provider := &Provider{ tf: shimProv, config: shimv2.NewSchemaMap(p.Schema), @@ -4715,7 +4681,7 @@ func TestPlanResourceChangeStateUpgrade(t *testing.T) { }, }, } - shimProv := shimv2.NewProvider(p, shimv2.WithPlanResourceChange(func(tfResourceType string) bool { return true })) + shimProv := shimv2.NewProvider(p) provider := &Provider{ tf: shimProv, config: shimv2.NewSchemaMap(p.Schema), @@ -4867,413 +4833,7 @@ func TestUnknowns(t *testing.T) { Schema: map[string]*schemav2.Schema{}, ResourcesMap: UnknownsSchema(), } - shimProv := shimv2.NewProvider(p, shimv2.WithPlanResourceChange(func(tfResourceType string) bool { return false })) - provider := &Provider{ - tf: shimProv, - config: shimv2.NewSchemaMap(p.Schema), - info: ProviderInfo{ - P: shimProv, - ResourcePrefix: "example", - Resources: map[string]*ResourceInfo{ - "example_resource": {Tok: "ExampleResource"}, - }, - }, - } - provider.initResourceMaps() - - t.Run("unknown for string prop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "stringProp":"04da6b54-80e4-46f7-96ec-b56ff0331ba9" - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) - - t.Run("unknown for set prop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "setProps":["04da6b54-80e4-46f7-96ec-b56ff0331ba9"] - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) - - t.Run("unknown for set block prop subprop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "setBlockProps":[{"prop":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"}] - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) - - t.Run("unknown for set block prop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "setBlockProps":["04da6b54-80e4-46f7-96ec-b56ff0331ba9"] - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) - - t.Run("unknown for set block prop collection", func(t *testing.T) { - // TODO[pulumi/pulumi-terraform-bridge#1885] - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "setBlockProps":"04da6b54-80e4-46f7-96ec-b56ff0331ba9" - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) - - t.Run("unknown for list prop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "listProps":["04da6b54-80e4-46f7-96ec-b56ff0331ba9"] - }, - "preview":true - }, - "response": { - "properties":{ - "id": "" - } - } - }`) - }) - - t.Run("unknown for list block prop subprop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "listBlockProps":[{"prop":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"}] - }, - "preview":true - }, - "response": { - "properties":{ - "id":"", - "listBlockProps":[{"prop":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"}] - } - } - }`) - }) - - t.Run("unknown for list block prop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "listBlockProps":["04da6b54-80e4-46f7-96ec-b56ff0331ba9"] - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) - - t.Run("unknown for list block prop collection", func(t *testing.T) { - // TODO[pulumi/pulumi-terraform-bridge#1885] - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "listBlockProps":"04da6b54-80e4-46f7-96ec-b56ff0331ba9" - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) - - t.Run("unknown for nested list prop", func(t *testing.T) { - // The unknownness gets promoted one level up. This seems to be TF behaviour, independent of PRC. - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "nestedListProps":[["04da6b54-80e4-46f7-96ec-b56ff0331ba9"]] - }, - "preview":true - }, - "response": { - "properties":{ - "id":"", - "nestedListProps":["04da6b54-80e4-46f7-96ec-b56ff0331ba9"] - } - } - }`) - }) - - t.Run("unknown for nested list block prop nested subprop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "nestedListBlockProps":[{"nestedProps":[{"prop":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"}]}] - }, - "preview":true - }, - "response": { - "properties":{ - "id":"", - "nestedListBlockProps":[{"nestedProps":[{"prop":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"}]}] - } - } - }`) - }) - - t.Run("unknown for nested list block nested prop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "nestedListBlockProps":[{"nestedProps":["04da6b54-80e4-46f7-96ec-b56ff0331ba9"]}] - }, - "preview":true - }, - "response": { - "properties":{ - "id":"", - "nestedListBlockProps":[{"nestedProps":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"}] - } - } - }`) - }) - - t.Run("unknown for nested list block prop nested collection", func(t *testing.T) { - // TODO[pulumi/pulumi-terraform-bridge#1885] - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "nestedListBlockProps":[{"nestedProps":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"}] - }, - "preview":true - }, - "response": { - "properties":{ - "id":"", - "nestedListBlockProps":[{"nestedProps":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"}] - } - } - }`) - }) - - t.Run("unknown for nested list block prop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "nestedListBlockProps":["04da6b54-80e4-46f7-96ec-b56ff0331ba9"] - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) - - t.Run("unknown for nested list block prop collection", func(t *testing.T) { - // TODO[pulumi/pulumi-terraform-bridge#1885] - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "nestedListBlockProps":"04da6b54-80e4-46f7-96ec-b56ff0331ba9" - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) - - t.Run("unknown for max items one prop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "maxItemsOneProp":"04da6b54-80e4-46f7-96ec-b56ff0331ba9" - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) - - t.Run("unknown for max items one block prop", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "maxItemsOneBlockProp":{"prop":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"} - }, - "preview":true - }, - "response": { - "properties":{ - "id":"", - "maxItemsOneBlockProp": {"prop":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"} - } - } - }`) - }) - - t.Run("unknown for max items one block", func(t *testing.T) { - testutils.Replay(t, provider, ` - { - "method": "/pulumirpc.ResourceProvider/Create", - "request": { - "urn": "urn:pulumi:dev::teststack::ExampleResource::exres", - "properties":{ - "__defaults":[], - "maxItemsOneBlockProp":"04da6b54-80e4-46f7-96ec-b56ff0331ba9" - }, - "preview":true - }, - "response": { - "properties":{ - "id":"" - } - } - }`) - }) -} - -func TestPlanResourceChangeUnknowns(t *testing.T) { - t.Parallel() - // Related to [pulumi/pulumi-terraform-bridge#1885] - // This test is to ensure that we can handle unknowns in the schema. - // Note that the behaviour here might not match TF and can NOT match TF completely - // as HCL has no way of expressing unknown blocks. - // We currently have a workaround in makeTerraformInputs where we convert unknown blocks - // to blocks of unknown. - // - // The structure is that for each property we inject an unknown at every level. - // For the block tests: - // _subprop is an unknown for the subproperty in the block object - // _prop is an unknown for the whole block - // _collection is an unknown for the whole collection - // The nested match the above convention but also iterate over the nested object. - - p := &schemav2.Provider{ - Schema: map[string]*schemav2.Schema{}, - ResourcesMap: UnknownsSchema(), - } - shimProv := shimv2.NewProvider(p, shimv2.WithPlanResourceChange(func(tfResourceType string) bool { return true })) + shimProv := shimv2.NewProvider(p) provider := &Provider{ tf: shimProv, config: shimv2.NewSchemaMap(p.Schema), diff --git a/pkg/tfbridge/tests/provider_test.go b/pkg/tfbridge/tests/provider_test.go index 837d281de..7f684d8f2 100644 --- a/pkg/tfbridge/tests/provider_test.go +++ b/pkg/tfbridge/tests/provider_test.go @@ -535,9 +535,7 @@ func TestRegress1932(t *testing.T) { }, }, }, - }, shimv2.WithPlanResourceChange(func(s string) bool { - return true - })), + }), Name: "aws", ResourcePrefix: "example", Resources: map[string]*tfbridge.ResourceInfo{ @@ -661,9 +659,7 @@ func TestReproMinimalDiffCycle(t *testing.T) { ResourcesMap: map[string]*schema.Resource{ "example_resource": resource, }, - }, shimv2.WithPlanResourceChange(func(tfResourceType string) bool { - return true - })), + }), Name: "testprov", ResourcePrefix: "example", Resources: map[string]*tfbridge.ResourceInfo{ diff --git a/pkg/tfshim/sdk-v2/provider.go b/pkg/tfshim/sdk-v2/provider.go index 5d2d41a59..88ff0d664 100644 --- a/pkg/tfshim/sdk-v2/provider.go +++ b/pkg/tfshim/sdk-v2/provider.go @@ -67,10 +67,6 @@ func NewProvider(p *schema.Provider, opts ...providerOption) shim.Provider { o, err := getProviderOptions(opts) contract.AssertNoErrorf(err, "provider options failed to apply") - if o.planResourceChangeFilter != nil { - return newProviderWithPlanResourceChange(p, prov, o.planResourceChangeFilter, o.planStateEdit) - } - return newProviderWithPlanResourceChange(p, prov, func(s string) bool { return true }, o.planStateEdit) } diff --git a/pkg/tfshim/sdk-v2/provider_options.go b/pkg/tfshim/sdk-v2/provider_options.go index 164fae247..dbdc38853 100644 --- a/pkg/tfshim/sdk-v2/provider_options.go +++ b/pkg/tfshim/sdk-v2/provider_options.go @@ -22,8 +22,7 @@ import ( ) type providerOptions struct { - planResourceChangeFilter func(string) bool - planStateEdit PlanStateEditFunc + planStateEdit PlanStateEditFunc } type providerOption func(providerOptions) (providerOptions, error) @@ -81,9 +80,11 @@ func getProviderOptions(opts []providerOption) (providerOptions, error) { // Selectively opt-in resources that pass the filter to using PlanResourceChange. Resources are // identified by their TF type name such as aws_ssm_document. +// +// Deprecated: this no longer has any effect. +// TODO[pulumi/pulumi-terraform-bridge#2593] clean up deprecation. func WithPlanResourceChange(filter func(tfResourceType string) bool) providerOption { //nolint:revive return func(opts providerOptions) (providerOptions, error) { - opts.planResourceChangeFilter = filter return opts, nil } }