mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-04 13:17:43 -06:00
034e944070
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package objchange
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/internal/configs/configschema"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
// AllBlockAttributesNull constructs a non-null cty.Value of the object type implied
|
|
// 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
|
|
func AllBlockAttributesNull(schema *configschema.Block) cty.Value {
|
|
// "All attributes null" happens to be the definition of EmptyValue for
|
|
// a Block, so we can just delegate to that.
|
|
return schema.EmptyValue()
|
|
}
|
|
|
|
// 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)
|
|
}
|