From 0c078140a2058fab0c4df341da356932f2ed75b2 Mon Sep 17 00:00:00 2001 From: Venelin Date: Fri, 12 Jul 2024 15:00:27 +0100 Subject: [PATCH 01/26] fix nested compute read --- pkg/tfbridge/schema.go | 6 +++- pkg/tfbridge/schema_test.go | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/pkg/tfbridge/schema.go b/pkg/tfbridge/schema.go index 43708f0fe..029e59583 100644 --- a/pkg/tfbridge/schema.go +++ b/pkg/tfbridge/schema.go @@ -1734,7 +1734,11 @@ func extractSchemaInputs( v := make(map[resource.PropertyKey]resource.PropertyValue, len(obj)) etfs, eps := elemSchemas(tfs, ps) for k, e := range obj { - v[k] = extractSchemaInputs(e, etfs, eps) + input := extractSchemaInputs(e, etfs, eps) + if input.IsNull() && !etfs.Required() { + continue + } + v[k] = input } // To match previous behavior, we insert the default key for Map types. diff --git a/pkg/tfbridge/schema_test.go b/pkg/tfbridge/schema_test.go index a641b4783..131573a6e 100644 --- a/pkg/tfbridge/schema_test.go +++ b/pkg/tfbridge/schema_test.go @@ -2172,6 +2172,61 @@ func TestRefreshExtractInputsFromOutputsMaxItemsOne(t *testing.T) { assert.NoError(t, err) } +func TestRefreshExtractInputsFromOutputsListOfObjects(t *testing.T) { + t.Parallel() + + ruleSetProps := resource.PropertyMap{ + "attachedDisks": resource.NewArrayProperty([]resource.PropertyValue{ + resource.NewObjectProperty(resource.PropertyMap{ + "name": resource.NewStringProperty("name1"), + "key256": resource.NewNullProperty(), + }), + }), + } + + ruleSetSchema := func() shim.SchemaMap { + blockList := func(elem schema.SchemaMap) shim.Schema { + s := schema.Schema{ + Type: shim.TypeList, + Optional: true, + Elem: (&schema.Resource{ + Schema: elem, + }).Shim(), + } + return s.Shim() + } + + return schema.SchemaMap{ + "attachedDisks": blockList(schema.SchemaMap{ + "name": (&schema.Schema{Type: shim.TypeString, Optional: true}).Shim(), + "key256": (&schema.Schema{Type: shim.TypeString, Computed: true}).Shim(), + }), + } + } + + ruleSetPs := func() map[string]*SchemaInfo { + return map[string]*SchemaInfo{ + "attachedDisks": { + Fields: map[string]*SchemaInfo{ + "name": {}, + "key256": {}, + }, + }, + } + } + + out, err := ExtractInputsFromOutputs(nil, ruleSetProps, + ruleSetSchema(), ruleSetPs(), false) + assert.NoError(t, err) + t.Logf("out: %v", out) + assert.True(t, out["attachedDisks"].ArrayValue()[0].ObjectValue().DeepEquals( + resource.PropertyMap{ + "__defaults": resource.NewArrayProperty([]resource.PropertyValue{}), + "name": resource.NewStringProperty("name1"), + }), + ) +} + func TestFailureReasonForMissingRequiredFields(t *testing.T) { // Define two required inputs tfProvider := makeTestTFProviderV1( From 841998f16e2c9550fb1d716e1b39eea6dc45536f Mon Sep 17 00:00:00 2001 From: Venelin Date: Fri, 12 Jul 2024 15:20:58 +0100 Subject: [PATCH 02/26] fix tests = () --- pkg/tfbridge/schema_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/tfbridge/schema_test.go b/pkg/tfbridge/schema_test.go index 131573a6e..bb9e43d47 100644 --- a/pkg/tfbridge/schema_test.go +++ b/pkg/tfbridge/schema_test.go @@ -17,6 +17,7 @@ package tfbridge import ( "context" "os" + "q" "sort" "strconv" "strings" @@ -2219,12 +2220,10 @@ func TestRefreshExtractInputsFromOutputsListOfObjects(t *testing.T) { ruleSetSchema(), ruleSetPs(), false) assert.NoError(t, err) t.Logf("out: %v", out) - assert.True(t, out["attachedDisks"].ArrayValue()[0].ObjectValue().DeepEquals( - resource.PropertyMap{ - "__defaults": resource.NewArrayProperty([]resource.PropertyValue{}), - "name": resource.NewStringProperty("name1"), - }), - ) + q.Q(out) + attachedDiskVal := out["attachedDisks"].ArrayValue()[0].ObjectValue() + _, ok := attachedDiskVal["key256"] + assert.False(t, ok) } func TestFailureReasonForMissingRequiredFields(t *testing.T) { From a2b4bf5226e43caefbb02ab10bfda5bead1064bc Mon Sep 17 00:00:00 2001 From: Venelin Date: Fri, 12 Jul 2024 15:27:02 +0100 Subject: [PATCH 03/26] remove debug logging --- pkg/tfbridge/schema_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/tfbridge/schema_test.go b/pkg/tfbridge/schema_test.go index bb9e43d47..df8b47b8d 100644 --- a/pkg/tfbridge/schema_test.go +++ b/pkg/tfbridge/schema_test.go @@ -17,7 +17,6 @@ package tfbridge import ( "context" "os" - "q" "sort" "strconv" "strings" @@ -2220,7 +2219,6 @@ func TestRefreshExtractInputsFromOutputsListOfObjects(t *testing.T) { ruleSetSchema(), ruleSetPs(), false) assert.NoError(t, err) t.Logf("out: %v", out) - q.Q(out) attachedDiskVal := out["attachedDisks"].ArrayValue()[0].ObjectValue() _, ok := attachedDiskVal["key256"] assert.False(t, ok) From baa894fd396ab1896be9708d60ab0898582497ea Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 15 Jul 2024 19:26:08 +0100 Subject: [PATCH 04/26] integraration tests --- pkg/tests/schema_pulumi_test.go | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/pkg/tests/schema_pulumi_test.go b/pkg/tests/schema_pulumi_test.go index 3b17a109d..e537d6bc9 100644 --- a/pkg/tests/schema_pulumi_test.go +++ b/pkg/tests/schema_pulumi_test.go @@ -1410,3 +1410,81 @@ Resources: }) } } + +func TestFullyComputedNestedAttribute(t *testing.T) { + resMap := map[string]*schema.Resource{ + "prov_test": { + Schema: map[string]*schema.Schema{ + "attached_disks": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Optional: true, + Type: schema.TypeString, + }, + "key256": { + Computed: true, + Type: schema.TypeString, + }, + }, + }, + }, + "top_level_computed": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + } + + importer := func(val any) func(context.Context, *schema.ResourceData, interface{}) ([]*schema.ResourceData, error) { + return func(ctx context.Context, rd *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) { + elMap := map[string]any{ + "name": "disk1", + "key256": val, + } + err := rd.Set("attached_disks", []map[string]any{elMap}) + require.NoError(t, err) + + err = rd.Set("top_level_computed", "computed_val") + require.NoError(t, err) + + return []*schema.ResourceData{rd}, nil + } + } + bridgedProvider := pulcheck.BridgedProvider(t, "prov", resMap) + + program := ` +name: test +runtime: yaml +` + for _, tc := range []struct { + name string + importVal any + }{ + { + "non-nil", + "val1", + }, + { + "nil", + nil, + }, + } { + t.Run(tc.name, func(t *testing.T) { + resMap["prov_test"].Importer = &schema.ResourceImporter{ + StateContext: importer(tc.importVal), + } + + pt := pulcheck.PulCheck(t, bridgedProvider, program) + + res := pt.Import("prov:index/test:Test", "res1", "id1", "") + + t.Logf(res.Stdout) + + require.NotContains(t, res.Stdout, "One or more imported inputs failed to validate") + }) + } +} From efe595d132af266191bca1149c081b19cf733623 Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 15 Jul 2024 19:26:44 +0100 Subject: [PATCH 05/26] fix object check in input extraction --- pkg/tfbridge/schema.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/tfbridge/schema.go b/pkg/tfbridge/schema.go index 029e59583..7287ee0f1 100644 --- a/pkg/tfbridge/schema.go +++ b/pkg/tfbridge/schema.go @@ -33,7 +33,6 @@ import ( shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema" - shimutil "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/util" ) // This file deals with translating between the Pulumi representations of a resource's configuration and state and the @@ -1722,9 +1721,9 @@ func extractSchemaInputs( return resource.NewArrayProperty(v) case state.IsObject(): obj := state.ObjectValue() - if tfflds, ok := shimutil.CastToTypeObject(tfs); ok { + if tfflds, ok := tfs.Elem().(shim.Resource); ok { return resource.NewProperty( - extractSchemaInputsObject(obj, tfflds, ps.Fields), + extractSchemaInputsObject(obj, tfflds.Schema(), ps.Fields), ) } @@ -1735,9 +1734,6 @@ func extractSchemaInputs( etfs, eps := elemSchemas(tfs, ps) for k, e := range obj { input := extractSchemaInputs(e, etfs, eps) - if input.IsNull() && !etfs.Required() { - continue - } v[k] = input } From 96a2f0b034807d60fdc894a05038a3abbb61aa82 Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 15 Jul 2024 19:28:34 +0100 Subject: [PATCH 06/26] add further todos related to wrong object check --- pkg/tfbridge/info/validate.go | 1 + pkg/tfbridge/info/validate_test.go | 1 + pkg/tfbridge/walk.go | 4 +++- pkg/tfshim/util/types.go | 8 ++++++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/tfbridge/info/validate.go b/pkg/tfbridge/info/validate.go index 7a7e49681..ab558bb54 100644 --- a/pkg/tfbridge/info/validate.go +++ b/pkg/tfbridge/info/validate.go @@ -116,6 +116,7 @@ func (c *infoCheck) checkProperty(path walk.SchemaPath, tfs shim.Schema, ps *Sch // To prevent confusion, users are barred from specifying information on // the associated Elem. All information should be specified directly on // this SchemaInfo. + // TODO: Wrong object check, what is the intention here? if obj, ok := util.CastToTypeObject(tfs); ok { if ps.Elem != nil { c.error(path, errElemForObject) diff --git a/pkg/tfbridge/info/validate_test.go b/pkg/tfbridge/info/validate_test.go index 80bab1bef..93edab933 100644 --- a/pkg/tfbridge/info/validate_test.go +++ b/pkg/tfbridge/info/validate_test.go @@ -39,6 +39,7 @@ func TestValidateNameOverride(t *testing.T) { Type: shim.TypeInt, }).Shim(), }).Shim(), + // TODO: This doesn't pass internal validate "object1": (&schema.Schema{ Type: shim.TypeMap, Elem: (&schema.Resource{ diff --git a/pkg/tfbridge/walk.go b/pkg/tfbridge/walk.go index e70bc8346..363565483 100644 --- a/pkg/tfbridge/walk.go +++ b/pkg/tfbridge/walk.go @@ -22,7 +22,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/tokens" "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" + shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/util" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/walk" md "github.com/pulumi/pulumi-terraform-bridge/v3/unstable/metadata" @@ -94,6 +94,7 @@ func propertyPathToSchemaPathInner( // Detect single-nested blocks (object types). // // This is the case where (schema & schema.Elem) ~ {x: T}. + // TODO: Fix - the object type function is wrong. if res, isRes := util.CastToTypeObject(schema); isRes { return propertyPathToSchemaPath(basePath, propertyPath, res, schemaInfo.Fields) } @@ -214,6 +215,7 @@ func schemaPathToPropertyPathInner( } // Detect single-nested blocks (object types). + // TODO: Fix if obj, isObject := util.CastToTypeObject(schema); isObject { return schemaPathToPropertyPath(basePath, schemaPath, obj, schemaInfo.Fields) } diff --git a/pkg/tfshim/util/types.go b/pkg/tfshim/util/types.go index 1edfd22bc..9e676c9fd 100644 --- a/pkg/tfshim/util/types.go +++ b/pkg/tfshim/util/types.go @@ -15,7 +15,7 @@ package util import ( - "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" + shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" ) // IsOfTypeMap detects schemas indicating a map[string,X] type. Due to a quirky encoding of @@ -25,6 +25,9 @@ func IsOfTypeMap(tfs shim.Schema) bool { if tfs == nil || tfs.Type() != shim.TypeMap { return false } + + // TODO: Can there be a map nested resource? + // This might be unused though _, hasResourceElem := tfs.Elem().(shim.Resource) return !hasResourceElem } @@ -38,7 +41,8 @@ func CastToTypeObject(tfs shim.Schema) (shim.SchemaMap, bool) { return nil, false } res, isRes := tfs.Elem().(shim.Resource) - if isRes && tfs.Type() == shim.TypeMap { + // TODO: Map nested resources are not a thing, AFAIK + if isRes { return res.Schema(), true } return nil, false From 48fd41bd16e2f7f933bb9390ab7619d52faabb6d Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 16 Jul 2024 12:23:39 +0300 Subject: [PATCH 07/26] Revert "add further todos related to wrong object check" This reverts commit 96a2f0b034807d60fdc894a05038a3abbb61aa82. --- pkg/tfbridge/info/validate.go | 1 - pkg/tfbridge/info/validate_test.go | 1 - pkg/tfbridge/walk.go | 4 +--- pkg/tfshim/util/types.go | 8 ++------ 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/pkg/tfbridge/info/validate.go b/pkg/tfbridge/info/validate.go index ab558bb54..7a7e49681 100644 --- a/pkg/tfbridge/info/validate.go +++ b/pkg/tfbridge/info/validate.go @@ -116,7 +116,6 @@ func (c *infoCheck) checkProperty(path walk.SchemaPath, tfs shim.Schema, ps *Sch // To prevent confusion, users are barred from specifying information on // the associated Elem. All information should be specified directly on // this SchemaInfo. - // TODO: Wrong object check, what is the intention here? if obj, ok := util.CastToTypeObject(tfs); ok { if ps.Elem != nil { c.error(path, errElemForObject) diff --git a/pkg/tfbridge/info/validate_test.go b/pkg/tfbridge/info/validate_test.go index 93edab933..80bab1bef 100644 --- a/pkg/tfbridge/info/validate_test.go +++ b/pkg/tfbridge/info/validate_test.go @@ -39,7 +39,6 @@ func TestValidateNameOverride(t *testing.T) { Type: shim.TypeInt, }).Shim(), }).Shim(), - // TODO: This doesn't pass internal validate "object1": (&schema.Schema{ Type: shim.TypeMap, Elem: (&schema.Resource{ diff --git a/pkg/tfbridge/walk.go b/pkg/tfbridge/walk.go index 363565483..e70bc8346 100644 --- a/pkg/tfbridge/walk.go +++ b/pkg/tfbridge/walk.go @@ -22,7 +22,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/tokens" "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" - shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/util" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/walk" md "github.com/pulumi/pulumi-terraform-bridge/v3/unstable/metadata" @@ -94,7 +94,6 @@ func propertyPathToSchemaPathInner( // Detect single-nested blocks (object types). // // This is the case where (schema & schema.Elem) ~ {x: T}. - // TODO: Fix - the object type function is wrong. if res, isRes := util.CastToTypeObject(schema); isRes { return propertyPathToSchemaPath(basePath, propertyPath, res, schemaInfo.Fields) } @@ -215,7 +214,6 @@ func schemaPathToPropertyPathInner( } // Detect single-nested blocks (object types). - // TODO: Fix if obj, isObject := util.CastToTypeObject(schema); isObject { return schemaPathToPropertyPath(basePath, schemaPath, obj, schemaInfo.Fields) } diff --git a/pkg/tfshim/util/types.go b/pkg/tfshim/util/types.go index 9e676c9fd..1edfd22bc 100644 --- a/pkg/tfshim/util/types.go +++ b/pkg/tfshim/util/types.go @@ -15,7 +15,7 @@ package util import ( - shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim" ) // IsOfTypeMap detects schemas indicating a map[string,X] type. Due to a quirky encoding of @@ -25,9 +25,6 @@ func IsOfTypeMap(tfs shim.Schema) bool { if tfs == nil || tfs.Type() != shim.TypeMap { return false } - - // TODO: Can there be a map nested resource? - // This might be unused though _, hasResourceElem := tfs.Elem().(shim.Resource) return !hasResourceElem } @@ -41,8 +38,7 @@ func CastToTypeObject(tfs shim.Schema) (shim.SchemaMap, bool) { return nil, false } res, isRes := tfs.Elem().(shim.Resource) - // TODO: Map nested resources are not a thing, AFAIK - if isRes { + if isRes && tfs.Type() == shim.TypeMap { return res.Schema(), true } return nil, false From 41499a0d2e1c57cf3cb32a0e53331d44f347728a Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 16 Jul 2024 12:26:01 +0300 Subject: [PATCH 08/26] revert logging change --- pkg/tfbridge/schema.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/tfbridge/schema.go b/pkg/tfbridge/schema.go index 7287ee0f1..c96becbd0 100644 --- a/pkg/tfbridge/schema.go +++ b/pkg/tfbridge/schema.go @@ -1733,8 +1733,7 @@ func extractSchemaInputs( v := make(map[resource.PropertyKey]resource.PropertyValue, len(obj)) etfs, eps := elemSchemas(tfs, ps) for k, e := range obj { - input := extractSchemaInputs(e, etfs, eps) - v[k] = input + v[k] = extractSchemaInputs(e, etfs, eps) } // To match previous behavior, we insert the default key for Map types. From 637504a347ea38d132f880f383d044ad673cee87 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 16 Jul 2024 12:29:28 +0300 Subject: [PATCH 09/26] lint --- pkg/tfbridge/schema_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/tfbridge/schema_test.go b/pkg/tfbridge/schema_test.go index df8b47b8d..d367e734b 100644 --- a/pkg/tfbridge/schema_test.go +++ b/pkg/tfbridge/schema_test.go @@ -2178,7 +2178,7 @@ func TestRefreshExtractInputsFromOutputsListOfObjects(t *testing.T) { ruleSetProps := resource.PropertyMap{ "attachedDisks": resource.NewArrayProperty([]resource.PropertyValue{ resource.NewObjectProperty(resource.PropertyMap{ - "name": resource.NewStringProperty("name1"), + "name": resource.NewStringProperty("name1"), "key256": resource.NewNullProperty(), }), }), @@ -2187,7 +2187,7 @@ func TestRefreshExtractInputsFromOutputsListOfObjects(t *testing.T) { ruleSetSchema := func() shim.SchemaMap { blockList := func(elem schema.SchemaMap) shim.Schema { s := schema.Schema{ - Type: shim.TypeList, + Type: shim.TypeList, Optional: true, Elem: (&schema.Resource{ Schema: elem, @@ -2198,8 +2198,8 @@ func TestRefreshExtractInputsFromOutputsListOfObjects(t *testing.T) { return schema.SchemaMap{ "attachedDisks": blockList(schema.SchemaMap{ - "name": (&schema.Schema{Type: shim.TypeString, Optional: true}).Shim(), - "key256": (&schema.Schema{Type: shim.TypeString, Computed: true}).Shim(), + "name": (&schema.Schema{Type: shim.TypeString, Optional: true}).Shim(), + "key256": (&schema.Schema{Type: shim.TypeString, Computed: true}).Shim(), }), } } @@ -2208,7 +2208,7 @@ func TestRefreshExtractInputsFromOutputsListOfObjects(t *testing.T) { return map[string]*SchemaInfo{ "attachedDisks": { Fields: map[string]*SchemaInfo{ - "name": {}, + "name": {}, "key256": {}, }, }, From 7e5b05342355043d7757f2a035475285fdee2047 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 16 Jul 2024 12:34:34 +0300 Subject: [PATCH 10/26] update test --- pkg/tfbridge/schema_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/tfbridge/schema_test.go b/pkg/tfbridge/schema_test.go index d367e734b..c0267ce1f 100644 --- a/pkg/tfbridge/schema_test.go +++ b/pkg/tfbridge/schema_test.go @@ -2787,7 +2787,6 @@ func TestExtractSchemaInputsNestedMaxItemsOne(t *testing.T) { "listObjects": resource.NewProperty([]resource.PropertyValue{ resource.NewProperty(resource.PropertyMap{ "__defaults": resource.NewProperty([]resource.PropertyValue{}), - "field1": resource.NewProperty(false), "listScalar": resource.NewProperty(1.0), }), }), From ff29def725cfd76f9ef083bcabb7cf512ea836da Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 16 Jul 2024 14:45:13 +0300 Subject: [PATCH 11/26] upgrade providertest package --- go.mod | 2 +- go.sum | 4 ++-- pkg/tests/go.mod | 2 +- pkg/tests/go.sum | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index c7e217ca8..4d9416e1b 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.14 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.8.0 diff --git a/go.sum b/go.sum index f07714892..9218ce368 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.14 h1:5QlAPAAs82jkQraHsJvq1xgVfC7xtW8sFJwv2pHgxQ8= +github.com/pulumi/providertest v0.0.14/go.mod h1:GcsqEGgSngwaNOD+kICJPIUQlnA911fGBU8HDlJvVL0= 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 671722fcd..e297641b5 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.14 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 35c379756..64946756a 100644 --- a/pkg/tests/go.sum +++ b/pkg/tests/go.sum @@ -1911,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.14 h1:5QlAPAAs82jkQraHsJvq1xgVfC7xtW8sFJwv2pHgxQ8= +github.com/pulumi/providertest v0.0.14/go.mod h1:GcsqEGgSngwaNOD+kICJPIUQlnA911fGBU8HDlJvVL0= 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 bf92dfdcc110b66c2232d68f0a0caae3f9504766 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 16 Jul 2024 14:58:19 +0300 Subject: [PATCH 12/26] go mod tidy --- dynamic/go.sum | 4 ++-- pf/go.sum | 4 ++-- pf/tests/go.mod | 2 +- pf/tests/go.sum | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dynamic/go.sum b/dynamic/go.sum index 4717c503a..babd861ac 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.14 h1:5QlAPAAs82jkQraHsJvq1xgVfC7xtW8sFJwv2pHgxQ8= +github.com/pulumi/providertest v0.0.14/go.mod h1:GcsqEGgSngwaNOD+kICJPIUQlnA911fGBU8HDlJvVL0= 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/go.sum b/pf/go.sum index 060ecc01a..3ba0f7d9e 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.14 h1:5QlAPAAs82jkQraHsJvq1xgVfC7xtW8sFJwv2pHgxQ8= +github.com/pulumi/providertest v0.0.14/go.mod h1:GcsqEGgSngwaNOD+kICJPIUQlnA911fGBU8HDlJvVL0= 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/pf/tests/go.mod b/pf/tests/go.mod index 79ff6e337..70e464272 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.14 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..0a5de9a57 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.14 h1:5QlAPAAs82jkQraHsJvq1xgVfC7xtW8sFJwv2pHgxQ8= +github.com/pulumi/providertest v0.0.14/go.mod h1:GcsqEGgSngwaNOD+kICJPIUQlnA911fGBU8HDlJvVL0= 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 43995112c9e9d2290c033e891756c283a49e308d Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 16 Jul 2024 15:12:05 +0300 Subject: [PATCH 13/26] remove note about CastToTypeObject --- pkg/tfbridge/schema.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/tfbridge/schema.go b/pkg/tfbridge/schema.go index c96becbd0..2d5277190 100644 --- a/pkg/tfbridge/schema.go +++ b/pkg/tfbridge/schema.go @@ -493,8 +493,6 @@ func (ctx *conversionContext) makeTerraformInput( var tfflds shim.SchemaMap - // We cannot use [shimutil.CastToTypeObject] because we have machinery that constructs invalid - // resource objects, such as [elemSchemas]. if tfs != nil { if r, ok := tfs.Elem().(shim.Resource); ok { tfflds = r.Schema() From f0a277b872890c26391f20cbffd820bbf6380a36 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 16 Jul 2024 15:13:41 +0300 Subject: [PATCH 14/26] add note to CastToTypeObject --- pkg/tfshim/util/types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/tfshim/util/types.go b/pkg/tfshim/util/types.go index 1edfd22bc..071b6bd8e 100644 --- a/pkg/tfshim/util/types.go +++ b/pkg/tfshim/util/types.go @@ -31,6 +31,7 @@ func IsOfTypeMap(tfs shim.Schema) bool { // CastToTypeObject performs a checked cast from shim.Schema to a TF object (a collection // of fields). +// Note that this is only valid for PF resources - in the TF SDK objects are not represented as maps // // See [shim.Schema.Elem()] comment for all the details of the encoding. func CastToTypeObject(tfs shim.Schema) (shim.SchemaMap, bool) { From 0260a544ba7b581929ba96fd07d813a0bb4b2fce Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 17 Jul 2024 17:05:41 +0300 Subject: [PATCH 15/26] remove unused pulumi schema override --- pkg/tfbridge/schema_test.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/pkg/tfbridge/schema_test.go b/pkg/tfbridge/schema_test.go index c0267ce1f..202e02cbe 100644 --- a/pkg/tfbridge/schema_test.go +++ b/pkg/tfbridge/schema_test.go @@ -2204,19 +2204,7 @@ func TestRefreshExtractInputsFromOutputsListOfObjects(t *testing.T) { } } - ruleSetPs := func() map[string]*SchemaInfo { - return map[string]*SchemaInfo{ - "attachedDisks": { - Fields: map[string]*SchemaInfo{ - "name": {}, - "key256": {}, - }, - }, - } - } - - out, err := ExtractInputsFromOutputs(nil, ruleSetProps, - ruleSetSchema(), ruleSetPs(), false) + out, err := ExtractInputsFromOutputs(nil, ruleSetProps, ruleSetSchema(), nil, false) assert.NoError(t, err) t.Logf("out: %v", out) attachedDiskVal := out["attachedDisks"].ArrayValue()[0].ObjectValue() From 4d31021717cac901fafd67e6eb7495a71d9e15bc Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 17 Jul 2024 17:07:05 +0300 Subject: [PATCH 16/26] make tidy --- pf/go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/pf/go.mod b/pf/go.mod index 871e069ed..022776055 100644 --- a/pf/go.mod +++ b/pf/go.mod @@ -16,7 +16,6 @@ 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 From 76191b9143d1274e3ac28d23107148af4115b2d3 Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 22 Jul 2024 13:43:29 +0300 Subject: [PATCH 17/26] remove unused schema options --- pkg/tfbridge/schema.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pkg/tfbridge/schema.go b/pkg/tfbridge/schema.go index e42b79e5c..e03e28209 100644 --- a/pkg/tfbridge/schema.go +++ b/pkg/tfbridge/schema.go @@ -292,7 +292,6 @@ type conversionContext struct { ProviderConfig resource.PropertyMap ApplyDefaults bool ApplyTFDefaults bool - ApplyMaxItemsOneDefaults bool Assets AssetTable UnknownCollectionsSupported bool } @@ -648,18 +647,6 @@ func (ctx *conversionContext) makeObjectTerraformInputs( return nil, err } - if tfs != nil && ctx.ApplyMaxItemsOneDefaults { - // Iterate over the TF schema and add an empty array for each nil MaxItemsOne property. - tfs.Range(func(key string, value shim.Schema) bool { - // First do a lookup of the name/info. - _, tfi, psi := getInfoFromTerraformName(key, tfs, ps, false) - if IsMaxItemsOne(tfi, psi) && result[key] == nil { - result[key] = []interface{}{} - } - return true - }) - } - if glog.V(5) { for k, v := range result { glog.V(5).Infof("Terraform input %v = %#v", k, v) From 39251cf162e9b391bb3156f671b8ff43195eec3c Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 22 Jul 2024 17:19:02 +0300 Subject: [PATCH 18/26] pf extract inputs from outputs tests --- pf/tests/extract_inputs_test.go | 421 ++++++++++++++++++++++++++++++++ 1 file changed, 421 insertions(+) create mode 100644 pf/tests/extract_inputs_test.go diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go new file mode 100644 index 000000000..5ddc4f9d5 --- /dev/null +++ b/pf/tests/extract_inputs_test.go @@ -0,0 +1,421 @@ +package tfbridgetests + +import ( + "context" + "testing" + + "github.com/hashicorp/terraform-plugin-framework/attr" + rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hexops/autogold/v2" + "github.com/pulumi/pulumi-terraform-bridge/pf/internal/schemashim" + pb "github.com/pulumi/pulumi-terraform-bridge/pf/tests/internal/providerbuilder" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi/sdk/v3/go/common/resource" + "github.com/stretchr/testify/require" +) + +func TestExtractInputsFromOutputsPF(t *testing.T) { + type testCase struct { + name string + props resource.PropertyMap + resSchema rschema.Schema + expect autogold.Value + } + + testCases := []testCase{ + { + name: "string", + props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.StringAttribute{Optional: true}, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: "bar"}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. + { + name: "string with default", + props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("bar")}, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: "bar"}, + }), + }, + { + name: "string with empty value", + props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": ""}), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.StringAttribute{Optional: true}, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "string computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.StringAttribute{Computed: true}, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "list attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": []interface{}{"bar"}}), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListAttribute{ + Optional: true, + ElementType: types.StringType, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: "bar", + }}}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. + { + name: "list attribute with default", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{"bar"}, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListAttribute{ + Optional: true, + ElementType: types.StringType, + Default: listdefault.StaticValue(types.ListValueMust(types.StringType, []attr.Value{types.StringValue("bar")})), + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: "bar", + }}}, + }), + }, + { + name: "list attribute computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{"bar"}, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListAttribute{ + ElementType: types.StringType, + Computed: true, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "list nested attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }, + }}}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. + { + name: "list nested attribute with defaults", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + Default: listdefault.StaticValue(types.ListValueMust(types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "bar": types.StringType, + }, + }, []attr.Value{types.ObjectValueMust( + map[string]attr.Type{ + "bar": types.StringType, + }, + map[string]attr.Value{ + "bar": types.StringValue("baz"), + }, + )})), + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }, + }}}, + }), + }, + { + name: "list nested attribute computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListNestedAttribute{ + Computed: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "list nested attribute nested computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}, + }}}, + }), + }, + { + name: "set nested attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.SetNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }, + }}}, + }), + }, + { + name: "map nested attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.MapNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }}, + }), + }, + { + name: "object attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ObjectAttribute{ + Optional: true, + AttributeTypes: map[string]attr.Type{ + "bar": types.StringType, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "single nested attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.SingleNestedAttribute{ + Optional: true, + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }}, + }), + }, + // BLOCKS + // { + // name: "list nested block", + // }, + // { + // name: "set nested block", + // }, + // { + // name: "single nested block", + // }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + prov := &pb.Provider{ + AllResources: []pb.Resource{ + { + Name: "test", + ResourceSchema: tc.resSchema, + }, + }, + } + + shimmedProvider := schemashim.ShimSchemaOnlyProvider(context.Background(), prov) + res := shimmedProvider.ResourcesMap().Get("_test") + result, err := tfbridge.ExtractInputsFromOutputs(nil, tc.props, res.Schema(), nil, false) + require.NoError(t, err) + tc.expect.Equal(t, result) + }) + } +} From b5ce289cf831c70de05404476671a37eba9db136 Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 22 Jul 2024 17:35:49 +0300 Subject: [PATCH 19/26] map tests --- pf/tests/extract_inputs_test.go | 192 +++++++++++++++++++++++++++++++- 1 file changed, 188 insertions(+), 4 deletions(-) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index 5ddc4f9d5..61f2cdf66 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/mapdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hexops/autogold/v2" @@ -101,7 +102,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}}, }), }, - // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { name: "list attribute with default", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -175,7 +176,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}}, }), }, - // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { name: "list nested attribute with defaults", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -221,6 +222,40 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}}, }), }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "list nested attribute with nested defaults", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("baz")}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }, + }}}, + }), + }, { name: "list nested attribute computed", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -311,7 +346,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { name: "map nested attribute", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ - "bar": "baz", + "key1": map[string]interface{}{"bar": "baz"}, }, }), resSchema: rschema.Schema{ @@ -334,7 +369,156 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + resource.PropertyKey("key1"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }}, + }}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "map nested attribute with default", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "key1": map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.MapNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + Default: mapdefault.StaticValue(types.MapValueMust( + types.ObjectType{ + AttrTypes: map[string]attr.Type{"bar": types.StringType}, + }, map[string]attr.Value{ + "key1": types.ObjectValueMust( + map[string]attr.Type{ + "bar": types.StringType, + }, + map[string]attr.Value{ + "bar": types.StringValue("baz"), + }, + ), + }, + )), + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("key1"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }}, + }}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "map nested attribute with nested default", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "key1": map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.MapNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("baz")}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("key1"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }}, + }}, + }), + }, + { + name: "map nested attribute computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "key1": map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.MapNestedAttribute{ + Computed: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "map nested attribute nested computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "key1": map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.MapNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("key1"): resource.PropertyValue{V: resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}}, }}, }), }, From e40f6a0f99f41171c612cf62e92e8182b2e4dcff Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 22 Jul 2024 17:40:39 +0300 Subject: [PATCH 20/26] more tests --- pf/tests/extract_inputs_test.go | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index 61f2cdf66..34dcae222 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -543,6 +543,27 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { V: []resource.PropertyValue{}, }}), }, + { + name: "object attribute computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ObjectAttribute{ + Computed: true, + AttributeTypes: map[string]attr.Type{ + "bar": types.StringType, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, { name: "single nested attribute", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -572,6 +593,49 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}, }), }, + { + name: "single nested attribute computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "single nested attribute nested computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.SingleNestedAttribute{ + Optional: true, + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: Add default tests here. // BLOCKS // { // name: "list nested block", From 4a59ef9afd43ead1d4694ee50b65488ce1c27ee7 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 23 Jul 2024 11:41:37 +0300 Subject: [PATCH 21/26] rename tests, add block tests --- pf/tests/extract_inputs_test.go | 335 ++++++++++++++++++++++++++++---- 1 file changed, 296 insertions(+), 39 deletions(-) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index 34dcae222..fda5368a9 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -27,8 +27,9 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { } testCases := []testCase{ + // ATTRIBUTES { - name: "string", + name: "string extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), resSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -44,7 +45,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. { - name: "string with default", + name: "string with default not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), resSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -55,11 +56,11 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("foo"): resource.PropertyValue{V: "bar"}, + resource.PropertyKey("foo"): resource.PropertyValue{V: "bar"}, // wrong }), }, { - name: "string with empty value", + name: "string with empty value not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": ""}), resSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -71,7 +72,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "string computed", + name: "string computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), resSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -83,7 +84,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "list attribute", + name: "list attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": []interface{}{"bar"}}), resSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -104,7 +105,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { - name: "list attribute with default", + name: "list attribute with default not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{"bar"}, }), @@ -122,12 +123,12 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { V: []resource.PropertyValue{}, }, resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ - V: "bar", + V: "bar", // wrong }}}, }), }, { - name: "list attribute computed", + name: "list attribute computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{"bar"}, }), @@ -144,7 +145,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "list nested attribute", + name: "list nested attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -178,7 +179,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { - name: "list nested attribute with defaults", + name: "list nested attribute with defaults not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -217,14 +218,14 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, // wrong }, }}}, }), }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { - name: "list nested attribute with nested defaults", + name: "list nested attribute with nested defaults not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -251,13 +252,13 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, // wrong }, }}}, }), }, { - name: "list nested attribute computed", + name: "list nested attribute computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -280,7 +281,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "list nested attribute nested computed", + name: "list nested attribute nested computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -310,7 +311,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }), }, { - name: "set nested attribute", + name: "set nested attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -343,7 +344,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }), }, { - name: "map nested attribute", + name: "map nested attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "key1": map[string]interface{}{"bar": "baz"}, @@ -380,7 +381,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { - name: "map nested attribute with default", + name: "map nested attribute with default not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "key1": map[string]interface{}{"bar": "baz"}, @@ -404,7 +405,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { "bar": types.StringType, }, map[string]attr.Value{ - "bar": types.StringValue("baz"), + "bar": types.StringValue("baz"), // wrong }, ), }, @@ -431,7 +432,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { - name: "map nested attribute with nested default", + name: "map nested attribute with nested default not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "key1": map[string]interface{}{"bar": "baz"}, @@ -461,13 +462,13 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, // wrong }}, }}, }), }, { - name: "map nested attribute computed", + name: "map nested attribute computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "key1": map[string]interface{}{"bar": "baz"}, @@ -490,7 +491,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "map nested attribute nested computed", + name: "map nested attribute nested computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "key1": map[string]interface{}{"bar": "baz"}, @@ -523,7 +524,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }), }, { - name: "object attribute", + name: "object attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", @@ -544,7 +545,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "object attribute computed", + name: "object attribute computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", @@ -565,7 +566,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "single nested attribute", + name: "single nested attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", @@ -594,7 +595,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }), }, { - name: "single nested attribute computed", + name: "single nested attribute computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", @@ -615,7 +616,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "single nested attribute nested computed", + name: "single nested attribute nested computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", @@ -635,17 +636,273 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { V: []resource.PropertyValue{}, }}), }, - // TODO[pulumi/pulumi-terraform-bridge#2218]: Add default tests here. + // TODO[pulumi/pulumi-terraform-bridge#2218]: Add missing defaults tests here once defaults are fixed. // BLOCKS - // { - // name: "list nested block", - // }, - // { - // name: "set nested block", - // }, - // { - // name: "single nested block", - // }, + { + name: "list nested block not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.ListNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "list nested block with defaults not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.ListNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("nested_value")}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + { + name: "list nested block computed not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.ListNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + { + name: "set nested block extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SetNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "set nested block with defaults not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SetNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("nested_value")}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + { + name: "set nested block computed not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SetNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + { + name: "single nested block extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": map[string]interface{}{"nested_field": "nested_value"}, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SingleNestedBlock{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "single nested block with default not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": map[string]interface{}{"nested_field": "nested_value"}, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SingleNestedBlock{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("nested_value")}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }}, + }), + }, + { + name: "single nested block computed not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": map[string]interface{}{"nested_field": "nested_value"}, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SingleNestedBlock{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, } for _, tc := range testCases { From 1b672b57ee910af25cb159f61cab6d73793aabf0 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 23 Jul 2024 12:17:27 +0300 Subject: [PATCH 22/26] fix pf tests --- pf/tests/extract_inputs_test.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index fda5368a9..73d23fa09 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -726,12 +726,9 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { V: []resource.PropertyValue{}, }, resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ - V: resource.PropertyMap{ - resource.PropertyKey("__defaults"): resource.PropertyValue{ - V: []resource.PropertyValue{}, - }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, - }, + V: resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}, }}}, }), }, @@ -823,12 +820,9 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { V: []resource.PropertyValue{}, }, resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ - V: resource.PropertyMap{ - resource.PropertyKey("__defaults"): resource.PropertyValue{ - V: []resource.PropertyValue{}, - }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, - }, + V: resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}, }}}, }), }, From 7fac4a1db3c97e0d4a65741971fca993d66a58a8 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 23 Jul 2024 12:20:03 +0300 Subject: [PATCH 23/26] add more todos --- pf/tests/extract_inputs_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index fda5368a9..cd6a4ffad 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -638,6 +638,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: Add missing defaults tests here once defaults are fixed. // BLOCKS + // TODO[pulumi/pulumi-terraform-bridge#2180]: This should not yield values for computed properties { name: "list nested block not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -665,7 +666,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong }, }}}, }), @@ -698,11 +699,12 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong }, }}}, }), }, + // TODO[pulumi/pulumi-terraform-bridge#2180]: This should not yield values for computed properties { name: "list nested block computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -730,7 +732,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong }, }}}, }), @@ -795,7 +797,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong }, }}}, }), @@ -881,7 +883,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong }}, }), }, From f07cf0cf9420a92f64024a34d468359ce18e0ee1 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 23 Jul 2024 12:23:47 +0300 Subject: [PATCH 24/26] fix todos --- pf/tests/extract_inputs_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index cd6a4ffad..c514a0423 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -638,9 +638,8 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: Add missing defaults tests here once defaults are fixed. // BLOCKS - // TODO[pulumi/pulumi-terraform-bridge#2180]: This should not yield values for computed properties { - name: "list nested block not extracted", + name: "list nested block extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "block_field": []interface{}{ map[string]interface{}{"nested_field": "nested_value"}, @@ -666,7 +665,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, }, }}}, }), @@ -802,6 +801,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}}, }), }, + // TODO[pulumi/pulumi-terraform-bridge#2180]: This should not yield values for computed properties { name: "set nested block computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -829,7 +829,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, //wrong }, }}}, }), From 08fc395b9091b225d7d71e57bf9974588c1dcdb6 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 23 Jul 2024 12:36:45 +0300 Subject: [PATCH 25/26] fix sdkv2 tests --- pkg/tfbridge/schema_test.go | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/pkg/tfbridge/schema_test.go b/pkg/tfbridge/schema_test.go index aa33eaa2d..10795d7b5 100644 --- a/pkg/tfbridge/schema_test.go +++ b/pkg/tfbridge/schema_test.go @@ -3704,7 +3704,6 @@ func TestExtractInputsFromOutputsSdkv2(t *testing.T) { // }, // expected: autogold.Expect(), // }, - // TODO[pulumi/pulumi-terraform-bridge#2180]: This is wrong as an input should not be produced for computed values. { name: "list block with computed element not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -3726,20 +3725,16 @@ func TestExtractInputsFromOutputsSdkv2(t *testing.T) { V: []resource.PropertyValue{}, }, resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ - V: resource.PropertyMap{ - resource.PropertyKey("__defaults"): resource.PropertyValue{ - V: []resource.PropertyValue{}, - }, - resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, - }, + V: resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}, }}}, }), }, - // TODO[pulumi/pulumi-terraform-bridge#2180]: This is wrong as an input should not be produced for computed values. { name: "list block max items one with computed element not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ - "foo": []interface{}{map[string]string{"bar": "baz"}}, + "foo": map[string]string{"bar": "baz"}, }), schemaMap: map[string]*schemav2.Schema{ "foo": { @@ -3753,16 +3748,9 @@ func TestExtractInputsFromOutputsSdkv2(t *testing.T) { }, }, }, - expected: autogold.Expect(resource.PropertyMap{ - resource.PropertyKey("__defaults"): resource.PropertyValue{ - V: []resource.PropertyValue{}, - }, - resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ - V: resource.PropertyMap{resource.PropertyKey("bar"): resource.PropertyValue{ - V: "baz", - }}, - }}}, - }), + expected: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), }, } From 89906ef933db60a27cc1dbe2bd2f6ce2278da8da Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 23 Jul 2024 12:37:39 +0300 Subject: [PATCH 26/26] remove note --- pkg/tfshim/util/types.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/tfshim/util/types.go b/pkg/tfshim/util/types.go index 071b6bd8e..79b7e333d 100644 --- a/pkg/tfshim/util/types.go +++ b/pkg/tfshim/util/types.go @@ -31,8 +31,6 @@ func IsOfTypeMap(tfs shim.Schema) bool { // CastToTypeObject performs a checked cast from shim.Schema to a TF object (a collection // of fields). -// Note that this is only valid for PF resources - in the TF SDK objects are not represented as maps -// // See [shim.Schema.Elem()] comment for all the details of the encoding. func CastToTypeObject(tfs shim.Schema) (shim.SchemaMap, bool) { if tfs == nil {