Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Infer optional & computed from parent
Browse files Browse the repository at this point in the history
Signed-off-by: Hasan Turken <turkenh@gmail.com>
  • Loading branch information
turkenh committed Mar 3, 2022
1 parent b54efc2 commit 1b91b16
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/types/conversion/tfjson/tfjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,35 @@ func schemaV2TypeFromCtyType(typ cty.Type, schema *schemav2.Schema) error { //no
et := typ.ElementType()
switch {
case et.IsPrimitiveType():
elemType = &schemav2.Schema{Type: primitiveToV2SchemaType(et)}
elemType = &schemav2.Schema{
Type: primitiveToV2SchemaType(et),
Computed: schema.Computed,
Optional: schema.Optional,
}
case et.IsCollectionType():
elemType = &schemav2.Schema{Type: collectionToV2SchemaType(et)}
elemType = &schemav2.Schema{
Type: collectionToV2SchemaType(et),
Computed: schema.Computed,
Optional: schema.Optional,
}
if err := schemaV2TypeFromCtyType(et, elemType.(*schemav2.Schema)); err != nil {
return err
}
case et.IsObjectType():
res := &schemav2.Resource{}
res.Schema = make(map[string]*schemav2.Schema, len(et.AttributeTypes()))
for key, attrTyp := range et.AttributeTypes() {
sch := &schemav2.Schema{}
if err := schemaV2TypeFromCtyType(attrTyp, sch); err != nil {
return err
sch := &schemav2.Schema{
Computed: schema.Computed,
Optional: schema.Optional,
}
if et.AttributeOptional(key) {
sch.Optional = true
}

if err := schemaV2TypeFromCtyType(attrTyp, sch); err != nil {
return err
}
res.Schema[key] = sch
}
elemType = res
Expand Down

0 comments on commit 1b91b16

Please sign in to comment.