From 1b91b16dcb0e91cd063e01cfe8c7f2fc201b4b14 Mon Sep 17 00:00:00 2001 From: Hasan Turken Date: Thu, 3 Mar 2022 15:38:03 +0300 Subject: [PATCH] Infer optional & computed from parent Signed-off-by: Hasan Turken --- pkg/types/conversion/tfjson/tfjson.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/types/conversion/tfjson/tfjson.go b/pkg/types/conversion/tfjson/tfjson.go index 99b5edb..d1aadb8 100644 --- a/pkg/types/conversion/tfjson/tfjson.go +++ b/pkg/types/conversion/tfjson/tfjson.go @@ -156,9 +156,17 @@ 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 } @@ -166,13 +174,17 @@ func schemaV2TypeFromCtyType(typ cty.Type, schema *schemav2.Schema) error { //no 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