2019-02-07 23:01:39 +01:00
|
|
|
package objchange
|
|
|
|
|
|
|
|
import (
|
2021-05-17 21:17:09 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/configs/configschema"
|
2019-02-07 23:01:39 +01:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
)
|
|
|
|
|
2021-02-10 14:31:21 +01:00
|
|
|
// AllBlockAttributesNull constructs a non-null cty.Value of the object type implied
|
2019-02-07 23:01:39 +01:00
|
|
|
// by the given schema that has all of its leaf attributes set to null and all
|
|
|
|
// of its nested block collections set to zero-length.
|
|
|
|
//
|
|
|
|
// This simulates what would result from decoding an empty configuration block
|
|
|
|
// with the given schema, except that it does not produce errors
|
2021-02-10 14:31:21 +01:00
|
|
|
func AllBlockAttributesNull(schema *configschema.Block) cty.Value {
|
2019-04-09 00:32:53 +02:00
|
|
|
// "All attributes null" happens to be the definition of EmptyValue for
|
|
|
|
// a Block, so we can just delegate to that.
|
|
|
|
return schema.EmptyValue()
|
2019-02-07 23:01:39 +01:00
|
|
|
}
|
2021-02-10 14:31:21 +01:00
|
|
|
|
|
|
|
// AllAttributesNull returns a cty.Value of the object type implied by the given
|
|
|
|
// attriubutes that has all of its leaf attributes set to null.
|
|
|
|
func AllAttributesNull(attrs map[string]*configschema.Attribute) cty.Value {
|
|
|
|
newAttrs := make(map[string]cty.Value, len(attrs))
|
|
|
|
|
|
|
|
for name, attr := range attrs {
|
|
|
|
if attr.NestedType != nil {
|
|
|
|
newAttrs[name] = AllAttributesNull(attr.NestedType.Attributes)
|
|
|
|
} else {
|
|
|
|
newAttrs[name] = cty.NullVal(attr.Type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cty.ObjectVal(newAttrs)
|
|
|
|
}
|