diff --git a/dynamic/go.sum b/dynamic/go.sum index 9b47555e8..7251dfc3e 100644 --- a/dynamic/go.sum +++ b/dynamic/go.sum @@ -760,8 +760,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/go.mod b/go.mod index b4a586540..55d37f1bc 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ 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/x/muxer v0.0.8 github.com/pulumi/pulumi-yaml v1.9.1 diff --git a/go.sum b/go.sum index 6602a6921..c6d6ded92 100644 --- a/go.sum +++ b/go.sum @@ -1902,8 +1902,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.9.1 h1:JPeI80M23SPactxgnCFS1casZlSr7ZhAXwSx4H55QQ4= diff --git a/pf/go.mod b/pf/go.mod index 022776055..871e069ed 100644 --- a/pf/go.mod +++ b/pf/go.mod @@ -16,6 +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.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 daff7932e..57ce63b48 100644 --- a/pf/go.sum +++ b/pf/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.9.1 h1:JPeI80M23SPactxgnCFS1casZlSr7ZhAXwSx4H55QQ4= diff --git a/pf/tests/go.mod b/pf/tests/go.mod index a7ad96671..4d50f7eae 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 2accbca38..f8039a0f9 100644 --- a/pf/tests/go.sum +++ b/pf/tests/go.sum @@ -1928,8 +1928,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.9.1 h1:JPeI80M23SPactxgnCFS1casZlSr7ZhAXwSx4H55QQ4= diff --git a/pkg/tests/go.mod b/pkg/tests/go.mod index 822603ab3..66f142a14 100644 --- a/pkg/tests/go.mod +++ b/pkg/tests/go.mod @@ -11,7 +11,7 @@ require ( 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 diff --git a/pkg/tests/go.sum b/pkg/tests/go.sum index c6290a4bc..6445712e6 100644 --- a/pkg/tests/go.sum +++ b/pkg/tests/go.sum @@ -1912,8 +1912,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.9.1 h1:JPeI80M23SPactxgnCFS1casZlSr7ZhAXwSx4H55QQ4= diff --git a/pkg/tfbridge/diff_test.go b/pkg/tfbridge/diff_test.go index 03f70d874..b6a61f599 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/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" @@ -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,137 @@ 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), + // Convert the inputs and state to TF config and resource attributes. + r := Resource{ + TF: shimv2.NewResource(res), + Schema: &ResourceInfo{Fields: info}, + } + + 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) { + t.Run("standard", 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) + 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) + }) }) - 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) - }) + for _, s := range setup { + t.Run(s.name, func(t *testing.T) { + // 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) + } + 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 +359,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 +376,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 +394,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 +412,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 +429,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 +446,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 +465,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 +484,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 +502,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 +520,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 +537,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 +554,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 +573,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 +592,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 +610,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 +628,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 +646,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 +663,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 +680,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 +699,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 +718,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 +736,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 +755,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 +774,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 +791,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 +808,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 +827,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 +846,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 +864,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 +886,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 +909,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 +930,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 +952,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 +971,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 +989,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 +1008,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 +1032,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 +1057,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 +1079,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 +1102,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 +1121,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 +1139,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 +1158,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 +1184,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 +1211,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 +1237,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 +1256,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 +1275,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 +1294,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 +1313,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 +1332,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 +1350,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 +1369,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 +1388,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 +1407,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 +1425,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 +1444,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 +1463,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 +1481,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 +1500,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 +1519,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 +1538,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 +1556,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 +1575,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 +1601,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 +1628,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 +1654,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 +1850,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 +1878,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 +1919,18 @@ 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 +1950,18 @@ 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 +1981,18 @@ 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 +2010,18 @@ 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 +2039,19 @@ 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"}, diff --git a/pkg/tfbridge/internal/test/schemaconvert/schemaconvert.go b/pkg/tfbridge/internal/test/schemaconvert/schemaconvert.go new file mode 100644 index 000000000..e6b15c443 --- /dev/null +++ b/pkg/tfbridge/internal/test/schemaconvert/schemaconvert.go @@ -0,0 +1,141 @@ +// 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 ( + 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 { + //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") + + //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") + + var 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, + } + } + + return &v1Schema.Resource{ + Schema: Sdkv2ToV1SchemaMap(sch.Schema), + SchemaVersion: sch.SchemaVersion, + DeprecationMessage: sch.DeprecationMessage, + Timeouts: timeouts, + } +} + +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, + //nolint:staticcheck + 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 +}