Skip to content

Commit

Permalink
nested_types singlemode object
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Hoehl <lukas.hoehl@stackit.cloud>
  • Loading branch information
hown3d committed Nov 8, 2024
1 parent 239e492 commit b557c7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pkg/types/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion pkg/types/conversion/tfjson/tfjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b557c7a

Please sign in to comment.