From 725ea594e9e814429719995033b6f28c5928c605 Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 3 Jul 2024 12:36:17 +0100 Subject: [PATCH 01/10] diff tests for sdkv2 --- go.mod | 5 +- go.sum | 4 +- pkg/tests/go.mod | 2 + pkg/tests/go.sum | 1 + pkg/tests/schemaconvert/schemaconvert.go | 130 ++++ pkg/tfbridge/diff_test.go | 775 +++++++++++------------ 6 files changed, 521 insertions(+), 396 deletions(-) create mode 100644 pkg/tests/schemaconvert/schemaconvert.go diff --git a/go.mod b/go.mod index f80338fb2..9ce42f612 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.21 replace github.com/pulumi/pulumi-terraform-bridge/x/muxer => ./x/muxer +replace github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tests => ./pkg/tests + require ( github.com/apparentlymart/go-cidr v1.1.0 github.com/blang/semver v3.5.1+incompatible @@ -36,8 +38,9 @@ require ( github.com/mitchellh/reflectwalk v1.0.2 github.com/pkg/errors v0.9.1 github.com/pulumi/inflector v0.1.1 - github.com/pulumi/providertest v0.0.11 + github.com/pulumi/providertest v0.0.13 github.com/pulumi/pulumi-java/pkg v0.11.0 + github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tests v0.0.0-00010101000000-000000000000 github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.8 github.com/pulumi/pulumi-yaml v1.8.0 github.com/pulumi/schema-tools v0.1.2 diff --git a/go.sum b/go.sum index f07714892..d8910077d 100644 --- a/go.sum +++ b/go.sum @@ -1901,8 +1901,8 @@ github.com/pulumi/esc v0.9.1 h1:HH5eEv8sgyxSpY5a8yePyqFXzA8cvBvapfH8457+mIs= github.com/pulumi/esc v0.9.1/go.mod h1:oEJ6bOsjYlQUpjf70GiX+CXn3VBmpwFDxUTlmtUN84c= github.com/pulumi/inflector v0.1.1 h1:dvlxlWtXwOJTUUtcYDvwnl6Mpg33prhK+7mzeF+SobA= github.com/pulumi/inflector v0.1.1/go.mod h1:HUFCjcPTz96YtTuUlwG3i3EZG4WlniBvR9bd+iJxCUY= -github.com/pulumi/providertest v0.0.11 h1:mg8MQ7Cq7+9XlHIkBD+aCqQO4mwAJEISngZgVdnQUe8= -github.com/pulumi/providertest v0.0.11/go.mod h1:HsxjVsytcMIuNj19w1lT2W0QXY0oReXl1+h6eD2JXP8= +github.com/pulumi/providertest v0.0.13 h1:9CAaoviOTuCVHDI15h3znXa5JsKYtXLYHIIdxOCzo3Y= +github.com/pulumi/providertest v0.0.13/go.mod h1:REAoaN+hGOtdWJGirfWYqcSjCejlbGfzyVTUuemJTuE= github.com/pulumi/pulumi-java/pkg v0.11.0 h1:Jw9gBvyfmfOMq/EkYDm9+zGPxsDAA8jfeMpHmtZ+1oA= github.com/pulumi/pulumi-java/pkg v0.11.0/go.mod h1:sXAk25P47AQVQL6ilAbFmRNgZykC7og/+87ihnqzFTc= github.com/pulumi/pulumi-yaml v1.8.0 h1:bhmidiCMMuzsJao5FE0UR69iF3WVKPCFrRkzjotFNn4= diff --git a/pkg/tests/go.mod b/pkg/tests/go.mod index 95d72e636..49959e926 100644 --- a/pkg/tests/go.mod +++ b/pkg/tests/go.mod @@ -8,6 +8,7 @@ replace ( ) require ( + github.com/hashicorp/terraform-plugin-sdk v1.7.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 github.com/hexops/autogold/v2 v2.2.1 github.com/hexops/valast v1.4.4 @@ -91,6 +92,7 @@ require ( github.com/ulikunitz/xz v0.5.10 // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect + github.com/zclconf/go-cty-yaml v1.0.1 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect go.opentelemetry.io/otel v1.24.0 // indirect diff --git a/pkg/tests/go.sum b/pkg/tests/go.sum index 35c379756..180bd055f 100644 --- a/pkg/tests/go.sum +++ b/pkg/tests/go.sum @@ -1651,6 +1651,7 @@ github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93 h1:T1Q6ag9tCwun16AW+ github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93/go.mod h1:n2TSygSNwsLJ76m8qFXTSc7beTb+auJxYdqrnoqwZWE= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8 h1:+RyjwU+Gnd/aTJBPZVDNm903eXVjjqhbaR4Ypx3xYyY= github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A= github.com/hashicorp/terraform-exec v0.20.0/go.mod h1:ckKGkJWbsNqFKV1itgMnE0hY9IYf1HoiekpuN0eWoDw= github.com/hashicorp/terraform-json v0.4.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU= diff --git a/pkg/tests/schemaconvert/schemaconvert.go b/pkg/tests/schemaconvert/schemaconvert.go new file mode 100644 index 000000000..6aca18e52 --- /dev/null +++ b/pkg/tests/schemaconvert/schemaconvert.go @@ -0,0 +1,130 @@ +package schemaconvert + +import ( + v1Schema "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + v2Schema "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" +) + +func Sdkv2ToV1Type(t v2Schema.ValueType) v1Schema.ValueType { + return v1Schema.ValueType(t) +} + +func Sdkv2ToV1SchemaOrResource(elem interface{}) interface{} { + switch elem := elem.(type) { + case nil: + return nil + case *v2Schema.Schema: + return Sdkv2ToV1Schema(elem) + case *v2Schema.Resource: + return Sdkv2ToV1Resource(elem) + default: + contract.Failf("unexpected type %T", elem) + return nil + } +} + +func Sdkv2ToV1Resource(sch *v2Schema.Resource) *v1Schema.Resource { + if sch.MigrateState != nil { + contract.Failf("MigrateState is not supported in conversion") + } + if sch.StateUpgraders != nil { + contract.Failf("StateUpgraders is not supported in conversion") + } + if sch.Create != nil || sch.Read != nil || sch.Update != nil || sch.Delete != nil || sch.Exists != nil || + sch.CreateContext != nil || sch.ReadContext != nil || sch.UpdateContext != nil || sch.DeleteContext != nil || sch.Importer != nil { + contract.Failf("runtime methods not supported in conversion") + } + + if sch.CustomizeDiff != nil { + contract.Failf("CustomizeDiff is not supported in conversion") + } + + timeouts := v1Schema.ResourceTimeout{} + if sch.Timeouts != nil { + timeouts = v1Schema.ResourceTimeout{ + Create: sch.Timeouts.Create, + Read: sch.Timeouts.Read, + Update: sch.Timeouts.Update, + Delete: sch.Timeouts.Delete, + Default: sch.Timeouts.Default, + } + } + timoutsPtr := &timeouts + if sch.Timeouts == nil { + timoutsPtr = nil + } + + return &v1Schema.Resource{ + Schema: Sdkv2ToV1SchemaMap(sch.Schema), + SchemaVersion: sch.SchemaVersion, + DeprecationMessage: sch.DeprecationMessage, + Timeouts: timoutsPtr, + } +} + +func Sdkv2ToV1Schema(sch *v2Schema.Schema) *v1Schema.Schema { + if sch.DiffSuppressFunc != nil { + contract.Failf("DiffSuppressFunc is not supported in conversion") + } + + defaultFunc := v1Schema.SchemaDefaultFunc(nil) + if sch.DefaultFunc != nil { + defaultFunc = func() (interface{}, error) { + return sch.DefaultFunc() + } + } + + stateFunc := v1Schema.SchemaStateFunc(nil) + if sch.StateFunc != nil { + stateFunc = func(i interface{}) string { + return sch.StateFunc(i) + } + } + + set := v1Schema.SchemaSetFunc(nil) + if sch.Set != nil { + set = func(i interface{}) int { + return sch.Set(i) + } + } + + validateFunc := v1Schema.SchemaValidateFunc(nil) + if sch.ValidateFunc != nil { + validateFunc = func(i interface{}, s string) ([]string, []error) { + return sch.ValidateFunc(i, s) + } + } + + return &v1Schema.Schema{ + Type: Sdkv2ToV1Type(sch.Type), + Optional: sch.Optional, + Required: sch.Required, + Default: sch.Default, + DefaultFunc: defaultFunc, + Description: sch.Description, + InputDefault: sch.InputDefault, + Computed: sch.Computed, + ForceNew: sch.ForceNew, + StateFunc: stateFunc, + Elem: Sdkv2ToV1SchemaOrResource(sch.Elem), + MaxItems: sch.MaxItems, + MinItems: sch.MinItems, + Set: set, + ComputedWhen: sch.ComputedWhen, + ConflictsWith: sch.ConflictsWith, + ExactlyOneOf: sch.ExactlyOneOf, + AtLeastOneOf: sch.AtLeastOneOf, + Deprecated: sch.Deprecated, + ValidateFunc: validateFunc, + Sensitive: sch.Sensitive, + } +} + +func Sdkv2ToV1SchemaMap(sch map[string]*v2Schema.Schema) map[string]*v1Schema.Schema { + res := make(map[string]*v1Schema.Schema) + for k, v := range sch { + res[k] = Sdkv2ToV1Schema(v) + } + return res +} diff --git a/pkg/tfbridge/diff_test.go b/pkg/tfbridge/diff_test.go index 03f70d874..fe4217f73 100644 --- a/pkg/tfbridge/diff_test.go +++ b/pkg/tfbridge/diff_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tests/schemaconvert" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" shimv1 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v1" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" @@ -197,15 +198,9 @@ func TestCustomizeDiff(t *testing.T) { }) } -func diffTest(t *testing.T, tfs map[string]*schema.Schema, info map[string]*SchemaInfo, - inputs, state map[string]interface{}, expected map[string]DiffKind, - expectedDiffChanges pulumirpc.DiffResponse_DiffChanges, - ignoreChanges ...string) { - ctx := context.Background() - - inputsMap := resource.NewPropertyMapFromMap(inputs) - stateMap := resource.NewPropertyMapFromMap(state) - +func v1Setup(tfs map[string]*schema.Schema) ( + shim.SchemaMap, Resource, shim.Provider, map[string]*SchemaInfo, +) { sch := shimv1.NewSchemaMap(tfs) // Fake up a TF resource and a TF provider. @@ -220,59 +215,126 @@ func diffTest(t *testing.T, tfs map[string]*schema.Schema, info map[string]*Sche "resource": res, }, }) + info := map[string]*SchemaInfo{} // Convert the inputs and state to TF config and resource attributes. r := Resource{ TF: shimv1.NewResource(res), Schema: &ResourceInfo{Fields: info}, } - tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap, - makeTerraformStateOptions{defaultZeroSchemaVersion: true}) - assert.NoError(t, err) - config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info) - assert.NoError(t, err) + return sch, r, provider, info +} - t.Run("standard", func(t *testing.T) { - tfDiff, err := provider.Diff(ctx, "resource", tfState, config, shim.DiffOptions{ - IgnoreChanges: newIgnoreChanges(ctx, sch, info, stateMap, inputsMap, ignoreChanges), - }) - assert.NoError(t, err) +func v1SetupFromv2Schema(tfs map[string]*v2Schema.Schema) ( + shim.SchemaMap, Resource, shim.Provider, map[string]*SchemaInfo, +) { + v1Schema := schemaconvert.Sdkv2ToV1SchemaMap(tfs) + return v1Setup(v1Schema) +} - // Convert the diff to a detailed diff and check the result. - diff, changes := makeDetailedDiff(ctx, sch, info, stateMap, inputsMap, tfDiff) - expectedDiff := map[string]*pulumirpc.PropertyDiff{} - for k, v := range expected { - expectedDiff[k] = &pulumirpc.PropertyDiff{Kind: v} - } - assert.Equal(t, expectedDiffChanges, changes) - assert.Equal(t, expectedDiff, diff) +func v2Setup(tfs map[string]*v2Schema.Schema) ( + shim.SchemaMap, Resource, shim.Provider, map[string]*SchemaInfo, +) { + sch := shimv2.NewSchemaMap(tfs) + + // Fake up a TF resource and a TF provider. + res := &v2Schema.Resource{ + Schema: tfs, + CustomizeDiff: func(_ context.Context, d *v2Schema.ResourceDiff, _ interface{}) error { + return d.SetNewComputed("outp") + }, + } + provider := shimv2.NewProvider(&v2Schema.Provider{ + ResourcesMap: map[string]*v2Schema.Resource{ + "resource": res, + }, }) + info := map[string]*SchemaInfo{} - // Add an ignoreChanges entry for each path in the expected diff, then re-convert the diff - // and check the result. - t.Run("withIgnoreAllExpected", func(t *testing.T) { - for k := range expected { - ignoreChanges = append(ignoreChanges, k) - } - tfDiff, err := provider.Diff(ctx, "resource", tfState, config, shim.DiffOptions{ - IgnoreChanges: newIgnoreChanges(ctx, sch, info, stateMap, inputsMap, ignoreChanges), - }) - assert.NoError(t, err) + // Convert the inputs and state to TF config and resource attributes. + r := Resource{ + TF: shimv2.NewResource(res), + Schema: &ResourceInfo{Fields: info}, + } - diff, changes := makeDetailedDiff(ctx, sch, info, stateMap, inputsMap, tfDiff) - assert.Equal(t, pulumirpc.DiffResponse_DIFF_NONE, changes) - assert.Equal(t, map[string]*pulumirpc.PropertyDiff{}, diff) - }) + return sch, r, provider, info +} + +// type for v2Setup and v1SetupFromv2Schema +type setupFunc func(tfs map[string]*v2Schema.Schema) ( + shim.SchemaMap, Resource, shim.Provider, map[string]*SchemaInfo) + +func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, + state map[string]interface{}, expected map[string]DiffKind, + expectedDiffChanges pulumirpc.DiffResponse_DiffChanges, + ignoreChanges ...string, +) { + ctx := context.Background() + + inputsMap := resource.NewPropertyMapFromMap(inputs) + stateMap := resource.NewPropertyMapFromMap(state) + + setup := []struct { + name string + setup setupFunc + }{ + {"v1", v1SetupFromv2Schema}, + {"v2", v2Setup}, + } + + for _, s := range setup { + t.Run(s.name, func(t *testing.T) { + sch, r, provider, info := s.setup(tfs) + + tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap, + makeTerraformStateOptions{defaultZeroSchemaVersion: true}) + assert.NoError(t, err) + + config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info) + assert.NoError(t, err) + + t.Run("standard", func(t *testing.T) { + tfDiff, err := provider.Diff(ctx, "resource", tfState, config, shim.DiffOptions{ + IgnoreChanges: newIgnoreChanges(ctx, sch, info, stateMap, inputsMap, ignoreChanges), + }) + assert.NoError(t, err) + + // Convert the diff to a detailed diff and check the result. + diff, changes := makeDetailedDiff(ctx, sch, info, stateMap, inputsMap, tfDiff) + expectedDiff := map[string]*pulumirpc.PropertyDiff{} + for k, v := range expected { + expectedDiff[k] = &pulumirpc.PropertyDiff{Kind: v} + } + assert.Equal(t, expectedDiffChanges, changes) + assert.Equal(t, expectedDiff, diff) + }) + + // Add an ignoreChanges entry for each path in the expected diff, then re-convert the diff + // and check the result. + t.Run("withIgnoreAllExpected", func(t *testing.T) { + for k := range expected { + ignoreChanges = append(ignoreChanges, k) + } + tfDiff, err := provider.Diff(ctx, "resource", tfState, config, shim.DiffOptions{ + IgnoreChanges: newIgnoreChanges(ctx, sch, info, stateMap, inputsMap, ignoreChanges), + }) + assert.NoError(t, err) + + diff, changes := makeDetailedDiff(ctx, sch, info, stateMap, inputsMap, tfDiff) + assert.Equal(t, pulumirpc.DiffResponse_DIFF_NONE, changes) + assert.Equal(t, map[string]*pulumirpc.PropertyDiff{}, diff) + }) + }) + } } func TestCustomDiffProducesReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeString}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeString}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "foo", }, @@ -286,11 +348,10 @@ func TestCustomDiffProducesReplace(t *testing.T) { func TestEmptyDiff(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeString}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeString}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "foo", }, @@ -304,11 +365,10 @@ func TestEmptyDiff(t *testing.T) { func TestSimpleAdd(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeString, Optional: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeString, Optional: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "foo", }, @@ -323,11 +383,10 @@ func TestSimpleAdd(t *testing.T) { func TestSimpleAddReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeString, Optional: true, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeString, Optional: true, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "foo", }, @@ -342,11 +401,10 @@ func TestSimpleAddReplace(t *testing.T) { func TestSimpleDelete(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeString, Optional: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeString, Optional: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": "foo", @@ -360,11 +418,10 @@ func TestSimpleDelete(t *testing.T) { func TestSimpleDeleteReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeString, Optional: true, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeString, Optional: true, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": "foo", @@ -378,11 +435,10 @@ func TestSimpleDeleteReplace(t *testing.T) { func TestSimpleUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeString}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeString}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "baz", }, @@ -398,11 +454,10 @@ func TestSimpleUpdate(t *testing.T) { func TestSimpleUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeString, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeString, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "baz", }, @@ -418,11 +473,10 @@ func TestSimpleUpdateReplace(t *testing.T) { func TestNestedAdd(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": map[string]interface{}{"nest": "foo"}, }, @@ -437,11 +491,10 @@ func TestNestedAdd(t *testing.T) { func TestNestedAddReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": map[string]interface{}{"nest": "foo"}, }, @@ -456,11 +509,10 @@ func TestNestedAddReplace(t *testing.T) { func TestNestedDelete(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": map[string]interface{}{"nest": "foo"}, @@ -474,11 +526,10 @@ func TestNestedDelete(t *testing.T) { func TestNestedDeleteReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": map[string]interface{}{"nest": "foo"}, @@ -492,11 +543,10 @@ func TestNestedDeleteReplace(t *testing.T) { func TestNestedUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": map[string]interface{}{"nest": "baz"}, }, @@ -512,11 +562,10 @@ func TestNestedUpdate(t *testing.T) { func TestNestedUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": map[string]interface{}{"nest": "baz"}, }, @@ -532,11 +581,10 @@ func TestNestedUpdateReplace(t *testing.T) { func TestNestedIgnore(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": map[string]interface{}{"nest": "baz"}, }, @@ -551,11 +599,10 @@ func TestNestedIgnore(t *testing.T) { func TestListAdd(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{"foo"}, }, @@ -570,11 +617,10 @@ func TestListAdd(t *testing.T) { func TestListAddReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{"foo"}, }, @@ -589,11 +635,10 @@ func TestListAddReplace(t *testing.T) { func TestListDelete(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": []interface{}{"foo"}, @@ -607,11 +652,10 @@ func TestListDelete(t *testing.T) { func TestListDeleteReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": []interface{}{"foo"}, @@ -625,11 +669,10 @@ func TestListDeleteReplace(t *testing.T) { func TestListUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{"baz"}, }, @@ -645,11 +688,10 @@ func TestListUpdate(t *testing.T) { func TestListUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{"baz"}, }, @@ -665,11 +707,10 @@ func TestListUpdateReplace(t *testing.T) { func TestListIgnore(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{"baz"}, }, @@ -684,11 +725,10 @@ func TestListIgnore(t *testing.T) { func TestMaxItemsOneListAdd(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, MaxItems: 1}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, MaxItems: 1}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "foo", }, @@ -704,11 +744,10 @@ func TestMaxItemsOneListAdd(t *testing.T) { func TestMaxItemsOneListAddReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true, MaxItems: 1}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true, MaxItems: 1}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "foo", }, @@ -724,11 +763,10 @@ func TestMaxItemsOneListAddReplace(t *testing.T) { func TestMaxItemsOneListDelete(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, MaxItems: 1}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, MaxItems: 1}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": "foo", @@ -742,11 +780,10 @@ func TestMaxItemsOneListDelete(t *testing.T) { func TestMaxItemsOneListDeleteReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true, MaxItems: 1}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true, MaxItems: 1}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": "foo", @@ -760,11 +797,10 @@ func TestMaxItemsOneListDeleteReplace(t *testing.T) { func TestMaxItemsOneListUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, MaxItems: 1}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, MaxItems: 1}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "baz", }, @@ -780,11 +816,10 @@ func TestMaxItemsOneListUpdate(t *testing.T) { func TestMaxItemsOneListUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true, MaxItems: 1}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true, MaxItems: 1}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "baz", }, @@ -800,11 +835,10 @@ func TestMaxItemsOneListUpdateReplace(t *testing.T) { func TestMaxItemsOneListIgnore(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, MaxItems: 1}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, MaxItems: 1}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "baz", }, @@ -819,15 +853,14 @@ func TestMaxItemsOneListIgnore(t *testing.T) { func TestSetAdd(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, + Type: v2Schema.TypeSet, Set: func(_ interface{}) int { return 0 }, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{"foo"}, }, @@ -842,16 +875,15 @@ func TestSetAdd(t *testing.T) { func TestSetAddReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, + Type: v2Schema.TypeSet, Set: func(_ interface{}) int { return 0 }, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{"foo"}, }, @@ -866,15 +898,14 @@ func TestSetAddReplace(t *testing.T) { func TestSetDelete(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, + Type: v2Schema.TypeSet, Set: func(_ interface{}) int { return 0 }, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": []interface{}{"foo"}, @@ -888,16 +919,15 @@ func TestSetDelete(t *testing.T) { func TestSetDeleteReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, + Type: v2Schema.TypeSet, Set: func(_ interface{}) int { return 0 }, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": []interface{}{"foo"}, @@ -911,11 +941,10 @@ func TestSetDeleteReplace(t *testing.T) { func TestSetUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{"baz"}, }, @@ -931,11 +960,10 @@ func TestSetUpdate(t *testing.T) { func TestSetIgnore(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{"baz"}, }, @@ -950,11 +978,10 @@ func TestSetIgnore(t *testing.T) { func TestSetUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{"baz"}, }, @@ -970,16 +997,15 @@ func TestSetUpdateReplace(t *testing.T) { func TestMaxItemsOneSetAdd(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, + Type: v2Schema.TypeSet, Set: func(_ interface{}) int { return 0 }, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, MaxItems: 1, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "foo", }, @@ -995,17 +1021,16 @@ func TestMaxItemsOneSetAdd(t *testing.T) { func TestMaxItemsOneSetAddReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, + Type: v2Schema.TypeSet, Set: func(_ interface{}) int { return 0 }, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, MaxItems: 1, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "foo", }, @@ -1021,16 +1046,15 @@ func TestMaxItemsOneSetAddReplace(t *testing.T) { func TestMaxItemsOneSetDelete(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, + Type: v2Schema.TypeSet, Set: func(_ interface{}) int { return 0 }, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, MaxItems: 1, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": "foo", @@ -1044,17 +1068,16 @@ func TestMaxItemsOneSetDelete(t *testing.T) { func TestMaxItemsOneSetDeleteReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, + Type: v2Schema.TypeSet, Set: func(_ interface{}) int { return 0 }, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, MaxItems: 1, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{}, map[string]interface{}{ "prop": "foo", @@ -1068,11 +1091,10 @@ func TestMaxItemsOneSetDeleteReplace(t *testing.T) { func TestMaxItemsOneSetUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, MaxItems: 1}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, MaxItems: 1}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "baz", }, @@ -1088,11 +1110,10 @@ func TestMaxItemsOneSetUpdate(t *testing.T) { func TestMaxItemsOneSetIgnore(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, MaxItems: 1}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, MaxItems: 1}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "baz", }, @@ -1107,11 +1128,10 @@ func TestMaxItemsOneSetIgnore(t *testing.T) { func TestMaxItemsOneSetUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true, MaxItems: 1}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true, MaxItems: 1}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": "baz", }, @@ -1127,18 +1147,17 @@ func TestMaxItemsOneSetUpdateReplace(t *testing.T) { func TestSetNestedUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true}, + Type: v2Schema.TypeSet, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true}, }, }, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": "baz"}}, }, @@ -1154,18 +1173,17 @@ func TestSetNestedUpdate(t *testing.T) { func TestSetNestedUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true, ForceNew: true}, + Type: v2Schema.TypeSet, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true, ForceNew: true}, }, }, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": "baz"}}, }, @@ -1182,18 +1200,17 @@ func TestSetNestedUpdateReplace(t *testing.T) { func TestSetNestedIgnore(t *testing.T) { for _, ignore := range []string{"prop[0]", "prop"} { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true}, + Type: v2Schema.TypeSet, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true}, }, }, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": "baz"}}, }, @@ -1209,11 +1226,10 @@ func TestSetNestedIgnore(t *testing.T) { func TestComputedSimpleUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeString}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeString}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": computedValue, }, @@ -1229,11 +1245,10 @@ func TestComputedSimpleUpdate(t *testing.T) { func TestComputedSimpleUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeString, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeString, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": computedValue, }, @@ -1249,11 +1264,10 @@ func TestComputedSimpleUpdateReplace(t *testing.T) { func TestComputedMapUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": computedValue, }, @@ -1269,11 +1283,10 @@ func TestComputedMapUpdate(t *testing.T) { func TestComputedNestedUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": map[string]interface{}{"nest": computedValue}, }, @@ -1289,11 +1302,10 @@ func TestComputedNestedUpdate(t *testing.T) { func TestComputedNestedUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": map[string]interface{}{"nest": computedValue}, }, @@ -1309,11 +1321,10 @@ func TestComputedNestedUpdateReplace(t *testing.T) { func TestComputedNestedIgnore(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeMap}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeMap}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": map[string]interface{}{"nest": computedValue}, }, @@ -1328,11 +1339,10 @@ func TestComputedNestedIgnore(t *testing.T) { func TestComputedListUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": computedValue, }, @@ -1348,11 +1358,10 @@ func TestComputedListUpdate(t *testing.T) { func TestComputedListElementUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{computedValue}, }, @@ -1368,11 +1377,10 @@ func TestComputedListElementUpdate(t *testing.T) { func TestComputedListElementUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{computedValue}, }, @@ -1388,11 +1396,10 @@ func TestComputedListElementUpdateReplace(t *testing.T) { func TestComputedListElementIgnore(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeList, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{computedValue}, }, @@ -1407,11 +1414,10 @@ func TestComputedListElementIgnore(t *testing.T) { func TestComputedSetUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": computedValue, }, @@ -1427,11 +1433,10 @@ func TestComputedSetUpdate(t *testing.T) { func TestNestedComputedSetUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{computedValue}, }, @@ -1447,11 +1452,10 @@ func TestNestedComputedSetUpdate(t *testing.T) { func TestNestedComputedSetAdd(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{computedValue}, }, @@ -1466,11 +1470,10 @@ func TestNestedComputedSetAdd(t *testing.T) { func TestNestedComputedSetUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{computedValue}, }, @@ -1486,11 +1489,10 @@ func TestNestedComputedSetUpdateReplace(t *testing.T) { func TestNestedComputedSetIntUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeInt}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeInt}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{computedValue}, }, @@ -1506,11 +1508,10 @@ func TestNestedComputedSetIntUpdate(t *testing.T) { func TestNestedComputedSetIntUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeInt}, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeInt}, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{computedValue}, }, @@ -1526,11 +1527,10 @@ func TestNestedComputedSetIntUpdateReplace(t *testing.T) { func TestNestedComputedSetIntAdd(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeInt}}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeInt}}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{computedValue}, }, @@ -1545,11 +1545,10 @@ func TestNestedComputedSetIntAdd(t *testing.T) { func TestComputedSetUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ - "prop": {Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true}, - "outp": {Type: schema.TypeString, Computed: true}, + map[string]*v2Schema.Schema{ + "prop": {Type: v2Schema.TypeSet, Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": computedValue, }, @@ -1565,18 +1564,17 @@ func TestComputedSetUpdateReplace(t *testing.T) { func TestComputedSetNestedUpdate(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true}, + Type: v2Schema.TypeSet, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true}, }, }, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": computedValue}}, }, @@ -1592,18 +1590,17 @@ func TestComputedSetNestedUpdate(t *testing.T) { func TestComputedSetNestedUpdateReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true, ForceNew: true}, + Type: v2Schema.TypeSet, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true, ForceNew: true}, }, }, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": computedValue}}, }, @@ -1620,18 +1617,17 @@ func TestComputedSetNestedUpdateReplace(t *testing.T) { func TestComputedSetNestedIgnore(t *testing.T) { for _, ignore := range []string{"prop[0]", "prop"} { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true}, + Type: v2Schema.TypeSet, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true}, }, }, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": computedValue}}, }, @@ -1647,24 +1643,23 @@ func TestComputedSetNestedIgnore(t *testing.T) { func TestRawElementNames(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeList, + Type: v2Schema.TypeList, Optional: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ "variables": { - Type: schema.TypeMap, + Type: v2Schema.TypeMap, Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, }, }, }, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": map[string]interface{}{ "variables": map[string]interface{}{ @@ -1844,19 +1839,19 @@ func TestCollectionsWithMultipleItems(t *testing.T) { }, } - runTestCase := func(t *testing.T, name string, typ schema.ValueType, inputs, state []interface{}, - expected map[string]DiffKind, expectedChanges pulumirpc.DiffResponse_DiffChanges) { + runTestCase := func(t *testing.T, name string, typ v2Schema.ValueType, inputs, state []interface{}, + expected map[string]DiffKind, expectedChanges pulumirpc.DiffResponse_DiffChanges, + ) { t.Run(name, func(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { Type: typ, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &v2Schema.Schema{Type: v2Schema.TypeString}, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": inputs, // inputs }, @@ -1872,32 +1867,31 @@ func TestCollectionsWithMultipleItems(t *testing.T) { t.Run("Set", func(t *testing.T) { for _, tc := range testCases { - runTestCase(t, tc.name, schema.TypeSet, tc.input, tc.state, tc.expectedDiffForSet, tc.expectedChangesForSet) + runTestCase(t, tc.name, v2Schema.TypeSet, tc.input, tc.state, tc.expectedDiffForSet, tc.expectedChangesForSet) } }) t.Run("List", func(t *testing.T) { for _, tc := range testCases { - runTestCase(t, tc.name, schema.TypeList, tc.input, tc.state, tc.expectedDiffForList, tc.expectedChangesForList) + runTestCase(t, tc.name, v2Schema.TypeList, tc.input, tc.state, tc.expectedDiffForList, tc.expectedChangesForList) } }) } func TestSetNestedAddReplace(t *testing.T) { diffTest(t, - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true}, + Type: v2Schema.TypeSet, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true}, }, }, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, - map[string]*SchemaInfo{}, map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": "baz"}}, }, @@ -1914,20 +1908,19 @@ func TestSetNestedAddReplace(t *testing.T) { func TestListNestedAddReplace(t *testing.T) { diffTest(t, // tfSchema - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeList, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true}, + Type: v2Schema.TypeList, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true}, }, }, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, // info - map[string]*SchemaInfo{}, // inputs map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": "foo"}}, @@ -1947,20 +1940,19 @@ func TestListNestedAddReplace(t *testing.T) { func TestListNestedUpdate(t *testing.T) { diffTest(t, // tfSchema - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeList, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true}, + Type: v2Schema.TypeList, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true}, }, }, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, // info - map[string]*SchemaInfo{}, // inputs map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": "foo"}}, @@ -1980,20 +1972,19 @@ func TestListNestedUpdate(t *testing.T) { func TestListNestedDeleteReplace(t *testing.T) { diffTest(t, // tfSchema - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeList, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true}, + Type: v2Schema.TypeList, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true}, }, }, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, // info - map[string]*SchemaInfo{}, // inputs map[string]interface{}{}, // state @@ -2011,20 +2002,19 @@ func TestListNestedDeleteReplace(t *testing.T) { func TestSetNestedDeleteReplace(t *testing.T) { diffTest(t, // tfSchema - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeSet, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true}, + Type: v2Schema.TypeSet, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true}, }, }, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, // info - map[string]*SchemaInfo{}, // inputs map[string]interface{}{}, // state @@ -2042,21 +2032,20 @@ func TestSetNestedDeleteReplace(t *testing.T) { func TestListNestedAddMaxItemsOne(t *testing.T) { diffTest(t, // tfSchema - map[string]*schema.Schema{ + map[string]*v2Schema.Schema{ "prop": { - Type: schema.TypeList, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nest": {Type: schema.TypeString, Required: true}, + Type: v2Schema.TypeList, + Elem: &v2Schema.Resource{ + Schema: map[string]*v2Schema.Schema{ + "nest": {Type: v2Schema.TypeString, Required: true}, }, }, MaxItems: 1, ForceNew: true, }, - "outp": {Type: schema.TypeString, Computed: true}, + "outp": {Type: v2Schema.TypeString, Computed: true}, }, // info - map[string]*SchemaInfo{}, // inputs map[string]interface{}{ "prop": map[string]interface{}{"nest": "foo"}, From d8395ffd0a69613dd987c3334a7a560766fff4b0 Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 3 Jul 2024 12:45:57 +0100 Subject: [PATCH 02/10] make new config and state for each test --- pkg/tfbridge/diff_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/tfbridge/diff_test.go b/pkg/tfbridge/diff_test.go index fe4217f73..896d2dc02 100644 --- a/pkg/tfbridge/diff_test.go +++ b/pkg/tfbridge/diff_test.go @@ -309,7 +309,19 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, assert.Equal(t, expectedDiffChanges, changes) assert.Equal(t, expectedDiff, diff) }) + }) + } + + for _, s := range setup { + t.Run(s.name, func(t *testing.T) { + sch, r, provider, info := s.setup(tfs) + tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap, + makeTerraformStateOptions{defaultZeroSchemaVersion: true}) + assert.NoError(t, err) + + config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info) + assert.NoError(t, err) // Add an ignoreChanges entry for each path in the expected diff, then re-convert the diff // and check the result. t.Run("withIgnoreAllExpected", func(t *testing.T) { From 9d054302a1e72c158fbdad3bb427d49c7d5d47a7 Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 3 Jul 2024 12:46:59 +0100 Subject: [PATCH 03/10] separate setup for each test --- pkg/tfbridge/diff_test.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/pkg/tfbridge/diff_test.go b/pkg/tfbridge/diff_test.go index 896d2dc02..d5251ab0d 100644 --- a/pkg/tfbridge/diff_test.go +++ b/pkg/tfbridge/diff_test.go @@ -285,16 +285,15 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, for _, s := range setup { t.Run(s.name, func(t *testing.T) { - sch, r, provider, info := s.setup(tfs) - - tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap, - makeTerraformStateOptions{defaultZeroSchemaVersion: true}) - assert.NoError(t, err) + t.Run("standard", func(t *testing.T) { + sch, r, provider, info := s.setup(tfs) - config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info) - assert.NoError(t, err) + tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap, + makeTerraformStateOptions{defaultZeroSchemaVersion: true}) + assert.NoError(t, err) - t.Run("standard", func(t *testing.T) { + config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info) + assert.NoError(t, err) tfDiff, err := provider.Diff(ctx, "resource", tfState, config, shim.DiffOptions{ IgnoreChanges: newIgnoreChanges(ctx, sch, info, stateMap, inputsMap, ignoreChanges), }) @@ -314,17 +313,17 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, for _, s := range setup { t.Run(s.name, func(t *testing.T) { - sch, r, provider, info := s.setup(tfs) - - tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap, - makeTerraformStateOptions{defaultZeroSchemaVersion: true}) - assert.NoError(t, err) - - config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info) - assert.NoError(t, err) // Add an ignoreChanges entry for each path in the expected diff, then re-convert the diff // and check the result. t.Run("withIgnoreAllExpected", func(t *testing.T) { + sch, r, provider, info := s.setup(tfs) + tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap, + makeTerraformStateOptions{defaultZeroSchemaVersion: true}) + assert.NoError(t, err) + + config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info) + assert.NoError(t, err) + for k := range expected { ignoreChanges = append(ignoreChanges, k) } From 0573b9bf26cae9d7cf538398fcc53388d2f0235d Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 3 Jul 2024 12:54:59 +0100 Subject: [PATCH 04/10] move schemaconvert --- go.mod | 3 --- pf/go.mod | 2 +- pf/go.sum | 4 ++-- pkg/tfbridge/diff_test.go | 7 +------ .../internal}/schemaconvert/schemaconvert.go | 0 5 files changed, 4 insertions(+), 12 deletions(-) rename pkg/{tests => tfbridge/internal}/schemaconvert/schemaconvert.go (100%) diff --git a/go.mod b/go.mod index 9ce42f612..62c00e88b 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,6 @@ go 1.21 replace github.com/pulumi/pulumi-terraform-bridge/x/muxer => ./x/muxer -replace github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tests => ./pkg/tests - require ( github.com/apparentlymart/go-cidr v1.1.0 github.com/blang/semver v3.5.1+incompatible @@ -40,7 +38,6 @@ require ( github.com/pulumi/inflector v0.1.1 github.com/pulumi/providertest v0.0.13 github.com/pulumi/pulumi-java/pkg v0.11.0 - github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tests v0.0.0-00010101000000-000000000000 github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.8 github.com/pulumi/pulumi-yaml v1.8.0 github.com/pulumi/schema-tools v0.1.2 diff --git a/pf/go.mod b/pf/go.mod index 01d2cc949..ab4ec9592 100644 --- a/pf/go.mod +++ b/pf/go.mod @@ -16,7 +16,7 @@ require ( github.com/hashicorp/terraform-plugin-go v0.22.0 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 - github.com/pulumi/providertest v0.0.11 + github.com/pulumi/providertest v0.0.13 github.com/pulumi/pulumi-terraform-bridge/v3 v3.86.0 github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.8 github.com/stretchr/testify v1.9.0 diff --git a/pf/go.sum b/pf/go.sum index 060ecc01a..8c1d18101 100644 --- a/pf/go.sum +++ b/pf/go.sum @@ -1900,8 +1900,8 @@ github.com/pulumi/esc v0.9.1 h1:HH5eEv8sgyxSpY5a8yePyqFXzA8cvBvapfH8457+mIs= github.com/pulumi/esc v0.9.1/go.mod h1:oEJ6bOsjYlQUpjf70GiX+CXn3VBmpwFDxUTlmtUN84c= github.com/pulumi/inflector v0.1.1 h1:dvlxlWtXwOJTUUtcYDvwnl6Mpg33prhK+7mzeF+SobA= github.com/pulumi/inflector v0.1.1/go.mod h1:HUFCjcPTz96YtTuUlwG3i3EZG4WlniBvR9bd+iJxCUY= -github.com/pulumi/providertest v0.0.11 h1:mg8MQ7Cq7+9XlHIkBD+aCqQO4mwAJEISngZgVdnQUe8= -github.com/pulumi/providertest v0.0.11/go.mod h1:HsxjVsytcMIuNj19w1lT2W0QXY0oReXl1+h6eD2JXP8= +github.com/pulumi/providertest v0.0.13 h1:9CAaoviOTuCVHDI15h3znXa5JsKYtXLYHIIdxOCzo3Y= +github.com/pulumi/providertest v0.0.13/go.mod h1:REAoaN+hGOtdWJGirfWYqcSjCejlbGfzyVTUuemJTuE= github.com/pulumi/pulumi-java/pkg v0.11.0 h1:Jw9gBvyfmfOMq/EkYDm9+zGPxsDAA8jfeMpHmtZ+1oA= github.com/pulumi/pulumi-java/pkg v0.11.0/go.mod h1:sXAk25P47AQVQL6ilAbFmRNgZykC7og/+87ihnqzFTc= github.com/pulumi/pulumi-yaml v1.8.0 h1:bhmidiCMMuzsJao5FE0UR69iF3WVKPCFrRkzjotFNn4= diff --git a/pkg/tfbridge/diff_test.go b/pkg/tfbridge/diff_test.go index d5251ab0d..d797dd886 100644 --- a/pkg/tfbridge/diff_test.go +++ b/pkg/tfbridge/diff_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tests/schemaconvert" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/internal/schemaconvert" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" shimv1 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v1" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" @@ -1931,7 +1931,6 @@ func TestListNestedAddReplace(t *testing.T) { }, "outp": {Type: v2Schema.TypeString, Computed: true}, }, - // info // inputs map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": "foo"}}, @@ -1963,7 +1962,6 @@ func TestListNestedUpdate(t *testing.T) { }, "outp": {Type: v2Schema.TypeString, Computed: true}, }, - // info // inputs map[string]interface{}{ "prop": []interface{}{map[string]interface{}{"nest": "foo"}}, @@ -1995,7 +1993,6 @@ func TestListNestedDeleteReplace(t *testing.T) { }, "outp": {Type: v2Schema.TypeString, Computed: true}, }, - // info // inputs map[string]interface{}{}, // state @@ -2025,7 +2022,6 @@ func TestSetNestedDeleteReplace(t *testing.T) { }, "outp": {Type: v2Schema.TypeString, Computed: true}, }, - // info // inputs map[string]interface{}{}, // state @@ -2056,7 +2052,6 @@ func TestListNestedAddMaxItemsOne(t *testing.T) { }, "outp": {Type: v2Schema.TypeString, Computed: true}, }, - // info // inputs map[string]interface{}{ "prop": map[string]interface{}{"nest": "foo"}, diff --git a/pkg/tests/schemaconvert/schemaconvert.go b/pkg/tfbridge/internal/schemaconvert/schemaconvert.go similarity index 100% rename from pkg/tests/schemaconvert/schemaconvert.go rename to pkg/tfbridge/internal/schemaconvert/schemaconvert.go From b5177ec134306d4b77bb24c931eb06aff4afc280 Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 3 Jul 2024 12:55:19 +0100 Subject: [PATCH 05/10] lint --- pkg/tfbridge/internal/schemaconvert/schemaconvert.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/tfbridge/internal/schemaconvert/schemaconvert.go b/pkg/tfbridge/internal/schemaconvert/schemaconvert.go index 6aca18e52..18f49fd23 100644 --- a/pkg/tfbridge/internal/schemaconvert/schemaconvert.go +++ b/pkg/tfbridge/internal/schemaconvert/schemaconvert.go @@ -32,7 +32,8 @@ func Sdkv2ToV1Resource(sch *v2Schema.Resource) *v1Schema.Resource { contract.Failf("StateUpgraders is not supported in conversion") } if sch.Create != nil || sch.Read != nil || sch.Update != nil || sch.Delete != nil || sch.Exists != nil || - sch.CreateContext != nil || sch.ReadContext != nil || sch.UpdateContext != nil || sch.DeleteContext != nil || sch.Importer != nil { + sch.CreateContext != nil || sch.ReadContext != nil || sch.UpdateContext != nil || + sch.DeleteContext != nil || sch.Importer != nil { contract.Failf("runtime methods not supported in conversion") } From 19736870b3a81f20c462fe34a8008470c0675442 Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 3 Jul 2024 13:01:28 +0100 Subject: [PATCH 06/10] lint --- .../internal/schemaconvert/schemaconvert.go | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/pkg/tfbridge/internal/schemaconvert/schemaconvert.go b/pkg/tfbridge/internal/schemaconvert/schemaconvert.go index 18f49fd23..95effb2e1 100644 --- a/pkg/tfbridge/internal/schemaconvert/schemaconvert.go +++ b/pkg/tfbridge/internal/schemaconvert/schemaconvert.go @@ -25,12 +25,14 @@ func Sdkv2ToV1SchemaOrResource(elem interface{}) interface{} { } func Sdkv2ToV1Resource(sch *v2Schema.Resource) *v1Schema.Resource { + //nolint:staticcheck if sch.MigrateState != nil { contract.Failf("MigrateState is not supported in conversion") } if sch.StateUpgraders != nil { contract.Failf("StateUpgraders is not supported in conversion") } + //nolint:staticcheck if sch.Create != nil || sch.Read != nil || sch.Update != nil || sch.Delete != nil || sch.Exists != nil || sch.CreateContext != nil || sch.ReadContext != nil || sch.UpdateContext != nil || sch.DeleteContext != nil || sch.Importer != nil { @@ -98,20 +100,21 @@ func Sdkv2ToV1Schema(sch *v2Schema.Schema) *v1Schema.Schema { } return &v1Schema.Schema{ - Type: Sdkv2ToV1Type(sch.Type), - Optional: sch.Optional, - Required: sch.Required, - Default: sch.Default, - DefaultFunc: defaultFunc, - Description: sch.Description, - InputDefault: sch.InputDefault, - Computed: sch.Computed, - ForceNew: sch.ForceNew, - StateFunc: stateFunc, - Elem: Sdkv2ToV1SchemaOrResource(sch.Elem), - MaxItems: sch.MaxItems, - MinItems: sch.MinItems, - Set: set, + Type: Sdkv2ToV1Type(sch.Type), + Optional: sch.Optional, + Required: sch.Required, + Default: sch.Default, + DefaultFunc: defaultFunc, + Description: sch.Description, + InputDefault: sch.InputDefault, + Computed: sch.Computed, + ForceNew: sch.ForceNew, + StateFunc: stateFunc, + Elem: Sdkv2ToV1SchemaOrResource(sch.Elem), + MaxItems: sch.MaxItems, + MinItems: sch.MinItems, + Set: set, + //nolint:staticcheck ComputedWhen: sch.ComputedWhen, ConflictsWith: sch.ConflictsWith, ExactlyOneOf: sch.ExactlyOneOf, From fc38c75b3c1f79383d61ff41d0dfb8b1908d75da Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 3 Jul 2024 13:09:04 +0100 Subject: [PATCH 07/10] add a v2 override --- pkg/tfbridge/diff_test.go | 97 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 7 deletions(-) diff --git a/pkg/tfbridge/diff_test.go b/pkg/tfbridge/diff_test.go index d797dd886..374fa9d69 100644 --- a/pkg/tfbridge/diff_test.go +++ b/pkg/tfbridge/diff_test.go @@ -105,7 +105,8 @@ func TestCustomizeDiff(t *testing.T) { for k, v := range expected { expectedDiff[k] = &pulumirpc.PropertyDiff{Kind: v} } - assert.Equal(t, pulumirpc.DiffResponse_DIFF_SOME, changes) + assert.Equal(t, + pulumirpc.DiffResponse_DIFF_SOME, changes) assert.Equal(t, expectedDiff, diff) }) @@ -267,6 +268,7 @@ type setupFunc func(tfs map[string]*v2Schema.Schema) ( func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, state map[string]interface{}, expected map[string]DiffKind, + expectedV2Override map[string]DiffKind, expectedDiffChanges pulumirpc.DiffResponse_DiffChanges, ignoreChanges ...string, ) { @@ -275,12 +277,18 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, inputsMap := resource.NewPropertyMapFromMap(inputs) stateMap := resource.NewPropertyMapFromMap(state) + v2Expected := expected + if expectedV2Override != nil { + v2Expected = expectedV2Override + } + setup := []struct { - name string - setup setupFunc + name string + setup setupFunc + expected map[string]DiffKind }{ - {"v1", v1SetupFromv2Schema}, - {"v2", v2Setup}, + {"v1", v1SetupFromv2Schema, expected}, + {"v2", v2Setup, v2Expected}, } for _, s := range setup { @@ -302,7 +310,7 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, // Convert the diff to a detailed diff and check the result. diff, changes := makeDetailedDiff(ctx, sch, info, stateMap, inputsMap, tfDiff) expectedDiff := map[string]*pulumirpc.PropertyDiff{} - for k, v := range expected { + for k, v := range s.expected { expectedDiff[k] = &pulumirpc.PropertyDiff{Kind: v} } assert.Equal(t, expectedDiffChanges, changes) @@ -324,7 +332,7 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info) assert.NoError(t, err) - for k := range expected { + for k := range s.expected { ignoreChanges = append(ignoreChanges, k) } tfDiff, err := provider.Diff(ctx, "resource", tfState, config, shim.DiffOptions{ @@ -354,6 +362,7 @@ func TestCustomDiffProducesReplace(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE) } @@ -371,6 +380,7 @@ func TestEmptyDiff(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE) } @@ -389,6 +399,7 @@ func TestSimpleAdd(t *testing.T) { map[string]DiffKind{ "prop": A, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -407,6 +418,7 @@ func TestSimpleAddReplace(t *testing.T) { map[string]DiffKind{ "prop": AR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -424,6 +436,7 @@ func TestSimpleDelete(t *testing.T) { map[string]DiffKind{ "prop": D, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -441,6 +454,7 @@ func TestSimpleDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop": DR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -460,6 +474,7 @@ func TestSimpleUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -479,6 +494,7 @@ func TestSimpleUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -497,6 +513,7 @@ func TestNestedAdd(t *testing.T) { map[string]DiffKind{ "prop.nest": A, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -515,6 +532,7 @@ func TestNestedAddReplace(t *testing.T) { map[string]DiffKind{ "prop.nest": AR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -532,6 +550,7 @@ func TestNestedDelete(t *testing.T) { map[string]DiffKind{ "prop.nest": D, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -549,6 +568,7 @@ func TestNestedDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop.nest": DR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -568,6 +588,7 @@ func TestNestedUpdate(t *testing.T) { map[string]DiffKind{ "prop.nest": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -587,6 +608,7 @@ func TestNestedUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop.nest": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -604,6 +626,7 @@ func TestNestedIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -623,6 +646,7 @@ func TestListAdd(t *testing.T) { map[string]DiffKind{ "prop[0]": A, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -641,6 +665,7 @@ func TestListAddReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": AR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -658,6 +683,7 @@ func TestListDelete(t *testing.T) { map[string]DiffKind{ "prop[0]": D, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -675,6 +701,7 @@ func TestListDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": DR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -694,6 +721,7 @@ func TestListUpdate(t *testing.T) { map[string]DiffKind{ "prop[0]": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -713,6 +741,7 @@ func TestListUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -730,6 +759,7 @@ func TestListIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -750,6 +780,7 @@ func TestMaxItemsOneListAdd(t *testing.T) { map[string]DiffKind{ "prop": A, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -769,6 +800,7 @@ func TestMaxItemsOneListAddReplace(t *testing.T) { map[string]DiffKind{ "prop": AR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -786,6 +818,7 @@ func TestMaxItemsOneListDelete(t *testing.T) { map[string]DiffKind{ "prop": D, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -803,6 +836,7 @@ func TestMaxItemsOneListDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop": DR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -822,6 +856,7 @@ func TestMaxItemsOneListUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -841,6 +876,7 @@ func TestMaxItemsOneListUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -858,6 +894,7 @@ func TestMaxItemsOneListIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -881,6 +918,7 @@ func TestSetAdd(t *testing.T) { map[string]DiffKind{ "prop[0]": A, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -904,6 +942,7 @@ func TestSetAddReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": AR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -925,6 +964,7 @@ func TestSetDelete(t *testing.T) { map[string]DiffKind{ "prop[0]": D, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -947,6 +987,7 @@ func TestSetDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": DR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -966,6 +1007,7 @@ func TestSetUpdate(t *testing.T) { map[string]DiffKind{ "prop[0]": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -983,6 +1025,7 @@ func TestSetIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -1003,6 +1046,7 @@ func TestSetUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1027,6 +1071,7 @@ func TestMaxItemsOneSetAdd(t *testing.T) { map[string]DiffKind{ "prop": A, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1052,6 +1097,7 @@ func TestMaxItemsOneSetAddReplace(t *testing.T) { map[string]DiffKind{ "prop": AR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1074,6 +1120,7 @@ func TestMaxItemsOneSetDelete(t *testing.T) { map[string]DiffKind{ "prop": D, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1097,6 +1144,7 @@ func TestMaxItemsOneSetDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop": DR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1116,6 +1164,7 @@ func TestMaxItemsOneSetUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1133,6 +1182,7 @@ func TestMaxItemsOneSetIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -1153,6 +1203,7 @@ func TestMaxItemsOneSetUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1179,6 +1230,7 @@ func TestSetNestedUpdate(t *testing.T) { map[string]DiffKind{ "prop[0].nest": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1205,6 +1257,7 @@ func TestSetNestedUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1230,6 +1283,7 @@ func TestSetNestedIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE, ignore) } @@ -1251,6 +1305,7 @@ func TestComputedSimpleUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1270,6 +1325,7 @@ func TestComputedSimpleUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1289,6 +1345,7 @@ func TestComputedMapUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1308,6 +1365,7 @@ func TestComputedNestedUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1327,6 +1385,7 @@ func TestComputedNestedUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1344,6 +1403,7 @@ func TestComputedNestedIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -1364,6 +1424,7 @@ func TestComputedListUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1383,6 +1444,7 @@ func TestComputedListElementUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1402,6 +1464,7 @@ func TestComputedListElementUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1419,6 +1482,7 @@ func TestComputedListElementIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -1439,6 +1503,7 @@ func TestComputedSetUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1458,6 +1523,7 @@ func TestNestedComputedSetUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1476,6 +1542,7 @@ func TestNestedComputedSetAdd(t *testing.T) { map[string]DiffKind{ "prop": A, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1495,6 +1562,7 @@ func TestNestedComputedSetUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1514,6 +1582,7 @@ func TestNestedComputedSetIntUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1533,6 +1602,7 @@ func TestNestedComputedSetIntUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1551,6 +1621,7 @@ func TestNestedComputedSetIntAdd(t *testing.T) { map[string]DiffKind{ "prop": A, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1570,6 +1641,7 @@ func TestComputedSetUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1596,6 +1668,7 @@ func TestComputedSetNestedUpdate(t *testing.T) { map[string]DiffKind{ "prop[0].nest": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1622,6 +1695,7 @@ func TestComputedSetNestedUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": UR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1647,6 +1721,7 @@ func TestComputedSetNestedIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, + nil, pulumirpc.DiffResponse_DIFF_NONE, ignore) } @@ -1688,6 +1763,7 @@ func TestRawElementNames(t *testing.T) { map[string]DiffKind{ "prop.variables.DYNAMODB_ROUTE_TABLE_NAME": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1871,6 +1947,7 @@ func TestCollectionsWithMultipleItems(t *testing.T) { "outp": "bar", }, expected, + nil, expectedChanges, ) }) @@ -1913,6 +1990,7 @@ func TestSetNestedAddReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": AR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1944,6 +2022,7 @@ func TestListNestedAddReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": AR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1975,6 +2054,7 @@ func TestListNestedUpdate(t *testing.T) { map[string]DiffKind{ "prop[0].nest": U, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -2004,6 +2084,7 @@ func TestListNestedDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": DR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -2033,6 +2114,7 @@ func TestSetNestedDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": DR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -2064,6 +2146,7 @@ func TestListNestedAddMaxItemsOne(t *testing.T) { map[string]DiffKind{ "prop.nest": AR, }, + nil, pulumirpc.DiffResponse_DIFF_SOME) } From 71cdfd07a14b223e4ed92a0d89690228976f44b2 Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 3 Jul 2024 13:43:07 +0100 Subject: [PATCH 08/10] Revert "add a v2 override" This reverts commit fc38c75b3c1f79383d61ff41d0dfb8b1908d75da. --- pkg/tfbridge/diff_test.go | 97 +++------------------------------------ 1 file changed, 7 insertions(+), 90 deletions(-) diff --git a/pkg/tfbridge/diff_test.go b/pkg/tfbridge/diff_test.go index 374fa9d69..d797dd886 100644 --- a/pkg/tfbridge/diff_test.go +++ b/pkg/tfbridge/diff_test.go @@ -105,8 +105,7 @@ func TestCustomizeDiff(t *testing.T) { for k, v := range expected { expectedDiff[k] = &pulumirpc.PropertyDiff{Kind: v} } - assert.Equal(t, - pulumirpc.DiffResponse_DIFF_SOME, changes) + assert.Equal(t, pulumirpc.DiffResponse_DIFF_SOME, changes) assert.Equal(t, expectedDiff, diff) }) @@ -268,7 +267,6 @@ type setupFunc func(tfs map[string]*v2Schema.Schema) ( func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, state map[string]interface{}, expected map[string]DiffKind, - expectedV2Override map[string]DiffKind, expectedDiffChanges pulumirpc.DiffResponse_DiffChanges, ignoreChanges ...string, ) { @@ -277,18 +275,12 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, inputsMap := resource.NewPropertyMapFromMap(inputs) stateMap := resource.NewPropertyMapFromMap(state) - v2Expected := expected - if expectedV2Override != nil { - v2Expected = expectedV2Override - } - setup := []struct { - name string - setup setupFunc - expected map[string]DiffKind + name string + setup setupFunc }{ - {"v1", v1SetupFromv2Schema, expected}, - {"v2", v2Setup, v2Expected}, + {"v1", v1SetupFromv2Schema}, + {"v2", v2Setup}, } for _, s := range setup { @@ -310,7 +302,7 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, // Convert the diff to a detailed diff and check the result. diff, changes := makeDetailedDiff(ctx, sch, info, stateMap, inputsMap, tfDiff) expectedDiff := map[string]*pulumirpc.PropertyDiff{} - for k, v := range s.expected { + for k, v := range expected { expectedDiff[k] = &pulumirpc.PropertyDiff{Kind: v} } assert.Equal(t, expectedDiffChanges, changes) @@ -332,7 +324,7 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs, config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info) assert.NoError(t, err) - for k := range s.expected { + for k := range expected { ignoreChanges = append(ignoreChanges, k) } tfDiff, err := provider.Diff(ctx, "resource", tfState, config, shim.DiffOptions{ @@ -362,7 +354,6 @@ func TestCustomDiffProducesReplace(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE) } @@ -380,7 +371,6 @@ func TestEmptyDiff(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE) } @@ -399,7 +389,6 @@ func TestSimpleAdd(t *testing.T) { map[string]DiffKind{ "prop": A, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -418,7 +407,6 @@ func TestSimpleAddReplace(t *testing.T) { map[string]DiffKind{ "prop": AR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -436,7 +424,6 @@ func TestSimpleDelete(t *testing.T) { map[string]DiffKind{ "prop": D, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -454,7 +441,6 @@ func TestSimpleDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop": DR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -474,7 +460,6 @@ func TestSimpleUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -494,7 +479,6 @@ func TestSimpleUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -513,7 +497,6 @@ func TestNestedAdd(t *testing.T) { map[string]DiffKind{ "prop.nest": A, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -532,7 +515,6 @@ func TestNestedAddReplace(t *testing.T) { map[string]DiffKind{ "prop.nest": AR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -550,7 +532,6 @@ func TestNestedDelete(t *testing.T) { map[string]DiffKind{ "prop.nest": D, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -568,7 +549,6 @@ func TestNestedDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop.nest": DR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -588,7 +568,6 @@ func TestNestedUpdate(t *testing.T) { map[string]DiffKind{ "prop.nest": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -608,7 +587,6 @@ func TestNestedUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop.nest": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -626,7 +604,6 @@ func TestNestedIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -646,7 +623,6 @@ func TestListAdd(t *testing.T) { map[string]DiffKind{ "prop[0]": A, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -665,7 +641,6 @@ func TestListAddReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": AR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -683,7 +658,6 @@ func TestListDelete(t *testing.T) { map[string]DiffKind{ "prop[0]": D, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -701,7 +675,6 @@ func TestListDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": DR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -721,7 +694,6 @@ func TestListUpdate(t *testing.T) { map[string]DiffKind{ "prop[0]": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -741,7 +713,6 @@ func TestListUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -759,7 +730,6 @@ func TestListIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -780,7 +750,6 @@ func TestMaxItemsOneListAdd(t *testing.T) { map[string]DiffKind{ "prop": A, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -800,7 +769,6 @@ func TestMaxItemsOneListAddReplace(t *testing.T) { map[string]DiffKind{ "prop": AR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -818,7 +786,6 @@ func TestMaxItemsOneListDelete(t *testing.T) { map[string]DiffKind{ "prop": D, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -836,7 +803,6 @@ func TestMaxItemsOneListDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop": DR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -856,7 +822,6 @@ func TestMaxItemsOneListUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -876,7 +841,6 @@ func TestMaxItemsOneListUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -894,7 +858,6 @@ func TestMaxItemsOneListIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -918,7 +881,6 @@ func TestSetAdd(t *testing.T) { map[string]DiffKind{ "prop[0]": A, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -942,7 +904,6 @@ func TestSetAddReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": AR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -964,7 +925,6 @@ func TestSetDelete(t *testing.T) { map[string]DiffKind{ "prop[0]": D, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -987,7 +947,6 @@ func TestSetDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": DR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1007,7 +966,6 @@ func TestSetUpdate(t *testing.T) { map[string]DiffKind{ "prop[0]": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1025,7 +983,6 @@ func TestSetIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -1046,7 +1003,6 @@ func TestSetUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop[0]": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1071,7 +1027,6 @@ func TestMaxItemsOneSetAdd(t *testing.T) { map[string]DiffKind{ "prop": A, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1097,7 +1052,6 @@ func TestMaxItemsOneSetAddReplace(t *testing.T) { map[string]DiffKind{ "prop": AR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1120,7 +1074,6 @@ func TestMaxItemsOneSetDelete(t *testing.T) { map[string]DiffKind{ "prop": D, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1144,7 +1097,6 @@ func TestMaxItemsOneSetDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop": DR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1164,7 +1116,6 @@ func TestMaxItemsOneSetUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1182,7 +1133,6 @@ func TestMaxItemsOneSetIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -1203,7 +1153,6 @@ func TestMaxItemsOneSetUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1230,7 +1179,6 @@ func TestSetNestedUpdate(t *testing.T) { map[string]DiffKind{ "prop[0].nest": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1257,7 +1205,6 @@ func TestSetNestedUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1283,7 +1230,6 @@ func TestSetNestedIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE, ignore) } @@ -1305,7 +1251,6 @@ func TestComputedSimpleUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1325,7 +1270,6 @@ func TestComputedSimpleUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1345,7 +1289,6 @@ func TestComputedMapUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1365,7 +1308,6 @@ func TestComputedNestedUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1385,7 +1327,6 @@ func TestComputedNestedUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1403,7 +1344,6 @@ func TestComputedNestedIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -1424,7 +1364,6 @@ func TestComputedListUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1444,7 +1383,6 @@ func TestComputedListElementUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1464,7 +1402,6 @@ func TestComputedListElementUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1482,7 +1419,6 @@ func TestComputedListElementIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE, "prop") } @@ -1503,7 +1439,6 @@ func TestComputedSetUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1523,7 +1458,6 @@ func TestNestedComputedSetUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1542,7 +1476,6 @@ func TestNestedComputedSetAdd(t *testing.T) { map[string]DiffKind{ "prop": A, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1562,7 +1495,6 @@ func TestNestedComputedSetUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1582,7 +1514,6 @@ func TestNestedComputedSetIntUpdate(t *testing.T) { map[string]DiffKind{ "prop": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1602,7 +1533,6 @@ func TestNestedComputedSetIntUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1621,7 +1551,6 @@ func TestNestedComputedSetIntAdd(t *testing.T) { map[string]DiffKind{ "prop": A, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1641,7 +1570,6 @@ func TestComputedSetUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1668,7 +1596,6 @@ func TestComputedSetNestedUpdate(t *testing.T) { map[string]DiffKind{ "prop[0].nest": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1695,7 +1622,6 @@ func TestComputedSetNestedUpdateReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": UR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1721,7 +1647,6 @@ func TestComputedSetNestedIgnore(t *testing.T) { "outp": "bar", }, map[string]DiffKind{}, - nil, pulumirpc.DiffResponse_DIFF_NONE, ignore) } @@ -1763,7 +1688,6 @@ func TestRawElementNames(t *testing.T) { map[string]DiffKind{ "prop.variables.DYNAMODB_ROUTE_TABLE_NAME": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -1947,7 +1871,6 @@ func TestCollectionsWithMultipleItems(t *testing.T) { "outp": "bar", }, expected, - nil, expectedChanges, ) }) @@ -1990,7 +1913,6 @@ func TestSetNestedAddReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": AR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -2022,7 +1944,6 @@ func TestListNestedAddReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": AR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -2054,7 +1975,6 @@ func TestListNestedUpdate(t *testing.T) { map[string]DiffKind{ "prop[0].nest": U, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -2084,7 +2004,6 @@ func TestListNestedDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": DR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -2114,7 +2033,6 @@ func TestSetNestedDeleteReplace(t *testing.T) { map[string]DiffKind{ "prop[0].nest": DR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } @@ -2146,7 +2064,6 @@ func TestListNestedAddMaxItemsOne(t *testing.T) { map[string]DiffKind{ "prop.nest": AR, }, - nil, pulumirpc.DiffResponse_DIFF_SOME) } From faeb1d417c58787187c6b92eda379d1fe7e658e3 Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 3 Jul 2024 13:44:00 +0100 Subject: [PATCH 09/10] go mod tidy --- dynamic/go.sum | 4 ++-- pf/tests/go.mod | 2 +- pf/tests/go.sum | 4 ++-- pkg/tests/go.mod | 4 +--- pkg/tests/go.sum | 5 ++--- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/dynamic/go.sum b/dynamic/go.sum index 4717c503a..d6c9c02ba 100644 --- a/dynamic/go.sum +++ b/dynamic/go.sum @@ -761,8 +761,8 @@ github.com/pulumi/esc v0.9.1 h1:HH5eEv8sgyxSpY5a8yePyqFXzA8cvBvapfH8457+mIs= github.com/pulumi/esc v0.9.1/go.mod h1:oEJ6bOsjYlQUpjf70GiX+CXn3VBmpwFDxUTlmtUN84c= github.com/pulumi/inflector v0.1.1 h1:dvlxlWtXwOJTUUtcYDvwnl6Mpg33prhK+7mzeF+SobA= github.com/pulumi/inflector v0.1.1/go.mod h1:HUFCjcPTz96YtTuUlwG3i3EZG4WlniBvR9bd+iJxCUY= -github.com/pulumi/providertest v0.0.11 h1:mg8MQ7Cq7+9XlHIkBD+aCqQO4mwAJEISngZgVdnQUe8= -github.com/pulumi/providertest v0.0.11/go.mod h1:HsxjVsytcMIuNj19w1lT2W0QXY0oReXl1+h6eD2JXP8= +github.com/pulumi/providertest v0.0.13 h1:9CAaoviOTuCVHDI15h3znXa5JsKYtXLYHIIdxOCzo3Y= +github.com/pulumi/providertest v0.0.13/go.mod h1:REAoaN+hGOtdWJGirfWYqcSjCejlbGfzyVTUuemJTuE= github.com/pulumi/pulumi-java/pkg v0.11.0 h1:Jw9gBvyfmfOMq/EkYDm9+zGPxsDAA8jfeMpHmtZ+1oA= github.com/pulumi/pulumi-java/pkg v0.11.0/go.mod h1:sXAk25P47AQVQL6ilAbFmRNgZykC7og/+87ihnqzFTc= github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.8 h1:mav2tSitA9BPJPLLahKgepHyYsMzwaTm4cvp0dcTMYw= diff --git a/pf/tests/go.mod b/pf/tests/go.mod index a88f7fcbe..98aa4b6e6 100644 --- a/pf/tests/go.mod +++ b/pf/tests/go.mod @@ -8,7 +8,7 @@ require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 github.com/hashicorp/terraform-provider-tls/shim v0.0.0-00010101000000-000000000000 github.com/hexops/autogold/v2 v2.2.1 - github.com/pulumi/providertest v0.0.11 + github.com/pulumi/providertest v0.0.13 github.com/pulumi/pulumi-terraform-bridge/pf v0.0.0 github.com/pulumi/pulumi-terraform-bridge/v3 v3.86.0 github.com/stretchr/testify v1.9.0 diff --git a/pf/tests/go.sum b/pf/tests/go.sum index 6458542e7..78a58c10b 100644 --- a/pf/tests/go.sum +++ b/pf/tests/go.sum @@ -1927,8 +1927,8 @@ github.com/pulumi/esc v0.9.1 h1:HH5eEv8sgyxSpY5a8yePyqFXzA8cvBvapfH8457+mIs= github.com/pulumi/esc v0.9.1/go.mod h1:oEJ6bOsjYlQUpjf70GiX+CXn3VBmpwFDxUTlmtUN84c= github.com/pulumi/inflector v0.1.1 h1:dvlxlWtXwOJTUUtcYDvwnl6Mpg33prhK+7mzeF+SobA= github.com/pulumi/inflector v0.1.1/go.mod h1:HUFCjcPTz96YtTuUlwG3i3EZG4WlniBvR9bd+iJxCUY= -github.com/pulumi/providertest v0.0.11 h1:mg8MQ7Cq7+9XlHIkBD+aCqQO4mwAJEISngZgVdnQUe8= -github.com/pulumi/providertest v0.0.11/go.mod h1:HsxjVsytcMIuNj19w1lT2W0QXY0oReXl1+h6eD2JXP8= +github.com/pulumi/providertest v0.0.13 h1:9CAaoviOTuCVHDI15h3znXa5JsKYtXLYHIIdxOCzo3Y= +github.com/pulumi/providertest v0.0.13/go.mod h1:REAoaN+hGOtdWJGirfWYqcSjCejlbGfzyVTUuemJTuE= github.com/pulumi/pulumi-java/pkg v0.11.0 h1:Jw9gBvyfmfOMq/EkYDm9+zGPxsDAA8jfeMpHmtZ+1oA= github.com/pulumi/pulumi-java/pkg v0.11.0/go.mod h1:sXAk25P47AQVQL6ilAbFmRNgZykC7og/+87ihnqzFTc= github.com/pulumi/pulumi-yaml v1.8.0 h1:bhmidiCMMuzsJao5FE0UR69iF3WVKPCFrRkzjotFNn4= diff --git a/pkg/tests/go.mod b/pkg/tests/go.mod index 49959e926..009070147 100644 --- a/pkg/tests/go.mod +++ b/pkg/tests/go.mod @@ -8,11 +8,10 @@ replace ( ) require ( - github.com/hashicorp/terraform-plugin-sdk v1.7.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 github.com/hexops/autogold/v2 v2.2.1 github.com/hexops/valast v1.4.4 - github.com/pulumi/providertest v0.0.12 + github.com/pulumi/providertest v0.0.13 github.com/pulumi/pulumi-terraform-bridge/v3 v3.80.0 github.com/stretchr/testify v1.9.0 gotest.tools v2.2.0+incompatible @@ -92,7 +91,6 @@ require ( github.com/ulikunitz/xz v0.5.10 // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - github.com/zclconf/go-cty-yaml v1.0.1 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect go.opentelemetry.io/otel v1.24.0 // indirect diff --git a/pkg/tests/go.sum b/pkg/tests/go.sum index 180bd055f..6ada63733 100644 --- a/pkg/tests/go.sum +++ b/pkg/tests/go.sum @@ -1651,7 +1651,6 @@ github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93 h1:T1Q6ag9tCwun16AW+ github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93/go.mod h1:n2TSygSNwsLJ76m8qFXTSc7beTb+auJxYdqrnoqwZWE= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8 h1:+RyjwU+Gnd/aTJBPZVDNm903eXVjjqhbaR4Ypx3xYyY= github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A= github.com/hashicorp/terraform-exec v0.20.0/go.mod h1:ckKGkJWbsNqFKV1itgMnE0hY9IYf1HoiekpuN0eWoDw= github.com/hashicorp/terraform-json v0.4.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU= @@ -1912,8 +1911,8 @@ github.com/pulumi/esc v0.9.1 h1:HH5eEv8sgyxSpY5a8yePyqFXzA8cvBvapfH8457+mIs= github.com/pulumi/esc v0.9.1/go.mod h1:oEJ6bOsjYlQUpjf70GiX+CXn3VBmpwFDxUTlmtUN84c= github.com/pulumi/inflector v0.1.1 h1:dvlxlWtXwOJTUUtcYDvwnl6Mpg33prhK+7mzeF+SobA= github.com/pulumi/inflector v0.1.1/go.mod h1:HUFCjcPTz96YtTuUlwG3i3EZG4WlniBvR9bd+iJxCUY= -github.com/pulumi/providertest v0.0.12 h1:UjcFQHHs4AGJyJqxhvC2q8yVQ7Li+UyCyP95HZcK03U= -github.com/pulumi/providertest v0.0.12/go.mod h1:REAoaN+hGOtdWJGirfWYqcSjCejlbGfzyVTUuemJTuE= +github.com/pulumi/providertest v0.0.13 h1:9CAaoviOTuCVHDI15h3znXa5JsKYtXLYHIIdxOCzo3Y= +github.com/pulumi/providertest v0.0.13/go.mod h1:REAoaN+hGOtdWJGirfWYqcSjCejlbGfzyVTUuemJTuE= github.com/pulumi/pulumi-java/pkg v0.11.0 h1:Jw9gBvyfmfOMq/EkYDm9+zGPxsDAA8jfeMpHmtZ+1oA= github.com/pulumi/pulumi-java/pkg v0.11.0/go.mod h1:sXAk25P47AQVQL6ilAbFmRNgZykC7og/+87ihnqzFTc= github.com/pulumi/pulumi-yaml v1.8.0 h1:bhmidiCMMuzsJao5FE0UR69iF3WVKPCFrRkzjotFNn4= From e76924146138d8f60271e1ff0ff8ab8dff21474a Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 16 Jul 2024 14:56:57 +0300 Subject: [PATCH 10/10] address review --- pkg/tfbridge/diff_test.go | 2 +- .../{ => test}/schemaconvert/schemaconvert.go | 65 ++++++++++--------- 2 files changed, 37 insertions(+), 30 deletions(-) rename pkg/tfbridge/internal/{ => test}/schemaconvert/schemaconvert.go (56%) diff --git a/pkg/tfbridge/diff_test.go b/pkg/tfbridge/diff_test.go index d797dd886..b6a61f599 100644 --- a/pkg/tfbridge/diff_test.go +++ b/pkg/tfbridge/diff_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/internal/schemaconvert" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/internal/test/schemaconvert" shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" shimv1 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v1" shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" diff --git a/pkg/tfbridge/internal/schemaconvert/schemaconvert.go b/pkg/tfbridge/internal/test/schemaconvert/schemaconvert.go similarity index 56% rename from pkg/tfbridge/internal/schemaconvert/schemaconvert.go rename to pkg/tfbridge/internal/test/schemaconvert/schemaconvert.go index 95effb2e1..e6b15c443 100644 --- a/pkg/tfbridge/internal/schemaconvert/schemaconvert.go +++ b/pkg/tfbridge/internal/test/schemaconvert/schemaconvert.go @@ -1,3 +1,20 @@ +// Copyright 2016-2024, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a test utility for converting sdkv2 schemas to sdkv1 to allow testing both without +// having to specify the schema twice. +// Only works with a part of the schema, will throw errors on unsupported features. package schemaconvert import ( @@ -6,46 +23,40 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" ) -func Sdkv2ToV1Type(t v2Schema.ValueType) v1Schema.ValueType { +func sdkv2ToV1Type(t v2Schema.ValueType) v1Schema.ValueType { return v1Schema.ValueType(t) } -func Sdkv2ToV1SchemaOrResource(elem interface{}) interface{} { +func sdkv2ToV1SchemaOrResource(elem interface{}) interface{} { switch elem := elem.(type) { case nil: return nil case *v2Schema.Schema: return Sdkv2ToV1Schema(elem) case *v2Schema.Resource: - return Sdkv2ToV1Resource(elem) + return sdkv2ToV1Resource(elem) default: contract.Failf("unexpected type %T", elem) return nil } } -func Sdkv2ToV1Resource(sch *v2Schema.Resource) *v1Schema.Resource { - //nolint:staticcheck - if sch.MigrateState != nil { - contract.Failf("MigrateState is not supported in conversion") - } - if sch.StateUpgraders != nil { - contract.Failf("StateUpgraders is not supported in conversion") - } - //nolint:staticcheck - if sch.Create != nil || sch.Read != nil || sch.Update != nil || sch.Delete != nil || sch.Exists != nil || - sch.CreateContext != nil || sch.ReadContext != nil || sch.UpdateContext != nil || - sch.DeleteContext != nil || sch.Importer != nil { - contract.Failf("runtime methods not supported in conversion") - } +func sdkv2ToV1Resource(sch *v2Schema.Resource) *v1Schema.Resource { + //nolint:staticcheck // deprecated + contract.Assertf(sch.MigrateState == nil, "MigrateState is not supported in conversion") + contract.Assertf(sch.StateUpgraders == nil, "StateUpgraders is not supported in conversion") - if sch.CustomizeDiff != nil { - contract.Failf("CustomizeDiff is not supported in conversion") - } + //nolint:staticcheck // deprecated + contract.Assertf(sch.Create == nil && sch.Read == nil && sch.Update == nil && sch.Delete == nil && sch.Exists == nil && + sch.CreateContext == nil && sch.ReadContext == nil && sch.UpdateContext == nil && + sch.DeleteContext == nil && sch.Importer == nil, + "runtime methods not supported in conversion") + + contract.Assertf(sch.CustomizeDiff == nil, "CustomizeDiff is not supported in conversion") - timeouts := v1Schema.ResourceTimeout{} + var timeouts *v1Schema.ResourceTimeout if sch.Timeouts != nil { - timeouts = v1Schema.ResourceTimeout{ + timeouts = &v1Schema.ResourceTimeout{ Create: sch.Timeouts.Create, Read: sch.Timeouts.Read, Update: sch.Timeouts.Update, @@ -53,16 +64,12 @@ func Sdkv2ToV1Resource(sch *v2Schema.Resource) *v1Schema.Resource { Default: sch.Timeouts.Default, } } - timoutsPtr := &timeouts - if sch.Timeouts == nil { - timoutsPtr = nil - } return &v1Schema.Resource{ Schema: Sdkv2ToV1SchemaMap(sch.Schema), SchemaVersion: sch.SchemaVersion, DeprecationMessage: sch.DeprecationMessage, - Timeouts: timoutsPtr, + Timeouts: timeouts, } } @@ -100,7 +107,7 @@ func Sdkv2ToV1Schema(sch *v2Schema.Schema) *v1Schema.Schema { } return &v1Schema.Schema{ - Type: Sdkv2ToV1Type(sch.Type), + Type: sdkv2ToV1Type(sch.Type), Optional: sch.Optional, Required: sch.Required, Default: sch.Default, @@ -110,7 +117,7 @@ func Sdkv2ToV1Schema(sch *v2Schema.Schema) *v1Schema.Schema { Computed: sch.Computed, ForceNew: sch.ForceNew, StateFunc: stateFunc, - Elem: Sdkv2ToV1SchemaOrResource(sch.Elem), + Elem: sdkv2ToV1SchemaOrResource(sch.Elem), MaxItems: sch.MaxItems, MinItems: sch.MinItems, Set: set,