diff --git a/pkg/types/builder.go b/pkg/types/builder.go index b6dcd9f9..e73c12ae 100644 --- a/pkg/types/builder.go +++ b/pkg/types/builder.go @@ -18,6 +18,7 @@ import ( "github.com/crossplane/upjet/pkg/config" "github.com/crossplane/upjet/pkg/schema/traverser" + conversiontfjson "github.com/crossplane/upjet/pkg/types/conversion/tfjson" ) const ( @@ -216,7 +217,7 @@ func (g *Builder) buildSchema(f *Field, cfg *config.Resource, names []string, cp return types.NewPointer(types.Universe.Lookup("int64").Type()), nil, nil case schema.TypeString: return types.NewPointer(types.Universe.Lookup("string").Type()), nil, nil - case schema.TypeMap, schema.TypeList, schema.TypeSet: + case schema.TypeMap, schema.TypeList, schema.TypeSet, conversiontfjson.SchemaTypeObject: names = append(names, f.Name.Camel) if f.Schema.Type != schema.TypeMap { // We don't want to have a many-to-many relationship in case of a Map, since we use SecretReference as @@ -312,7 +313,7 @@ func (g *Builder) buildSchema(f *Field, cfg *config.Resource, names []string, cp } // if the singleton list is to be replaced by an embedded object - if cfg.SchemaElementOptions.EmbeddedObject(cpath) { + if cfg.SchemaElementOptions.EmbeddedObject(cpath) || f.Schema.Type == conversiontfjson.SchemaTypeObject { return types.NewPointer(elemType), types.NewPointer(initElemType), nil } // NOTE(muvaf): Maps and slices are already pointers, so we don't need to diff --git a/pkg/types/conversion/tfjson/tfjson.go b/pkg/types/conversion/tfjson/tfjson.go index dac92bfb..3009ef2a 100644 --- a/pkg/types/conversion/tfjson/tfjson.go +++ b/pkg/types/conversion/tfjson/tfjson.go @@ -11,6 +11,11 @@ import ( "github.com/zclconf/go-cty/cty" ) +// SchemaTypeObject is the exported version of schema.typeObject to support +// nested types. +// TODO:remove once not dependent of terrafom sdkv2 schema +const SchemaTypeObject = schemav2.ValueType(9) + // GetV2ResourceMap converts input resource schemas with // "terraform-json" representation to terraform-plugin-sdk representation which // is what Upjet expects today. @@ -93,7 +98,7 @@ func tfJSONNestedAttributeTypeToV2Schema(na *tfjson.SchemaNestedAttributeType) * case tfjson.SchemaNestingModeMap: v2sch.Type = schemav2.TypeMap case tfjson.SchemaNestingModeSingle: - v2sch.Type = schemav2.TypeList + v2sch.Type = SchemaTypeObject v2sch.MinItems = 0 v2sch.Required = hasNestedAttributeRequiredChild(na) v2sch.Optional = !v2sch.Required