kubeform.dev/terraform-backend-sdk@v0.0.0-20220310143633-45f07fe731c5/plans/objchange/all_null.go (about) 1 package objchange 2 3 import ( 4 "kubeform.dev/terraform-backend-sdk/configs/configschema" 5 "github.com/zclconf/go-cty/cty" 6 ) 7 8 // AllBlockAttributesNull constructs a non-null cty.Value of the object type implied 9 // by the given schema that has all of its leaf attributes set to null and all 10 // of its nested block collections set to zero-length. 11 // 12 // This simulates what would result from decoding an empty configuration block 13 // with the given schema, except that it does not produce errors 14 func AllBlockAttributesNull(schema *configschema.Block) cty.Value { 15 // "All attributes null" happens to be the definition of EmptyValue for 16 // a Block, so we can just delegate to that. 17 return schema.EmptyValue() 18 } 19 20 // AllAttributesNull returns a cty.Value of the object type implied by the given 21 // attriubutes that has all of its leaf attributes set to null. 22 func AllAttributesNull(attrs map[string]*configschema.Attribute) cty.Value { 23 newAttrs := make(map[string]cty.Value, len(attrs)) 24 25 for name, attr := range attrs { 26 if attr.NestedType != nil { 27 newAttrs[name] = AllAttributesNull(attr.NestedType.Attributes) 28 } else { 29 newAttrs[name] = cty.NullVal(attr.Type) 30 } 31 } 32 return cty.ObjectVal(newAttrs) 33 }