4 "github.com/zclconf/go-cty/cty"
7 // EmptyValue returns the "empty value" for the recieving block, which for
8 // a block type is a non-null object where all of the attribute values are
9 // the empty values of the block's attributes and nested block types.
11 // In other words, it returns the value that would be returned if an empty
12 // block were decoded against the recieving schema, assuming that no required
13 // attribute or block constraints were honored.
14 func (b *Block) EmptyValue() cty.Value {
15 vals := make(map[string]cty.Value)
16 for name, attrS := range b.Attributes {
17 vals[name] = attrS.EmptyValue()
19 for name, blockS := range b.BlockTypes {
20 vals[name] = blockS.EmptyValue()
22 return cty.ObjectVal(vals)
25 // EmptyValue returns the "empty value" for the receiving attribute, which is
26 // the value that would be returned if there were no definition of the attribute
27 // at all, ignoring any required constraint.
28 func (a *Attribute) EmptyValue() cty.Value {
29 return cty.NullVal(a.Type)
32 // EmptyValue returns the "empty value" for when there are zero nested blocks
33 // present of the receiving type.
34 func (b *NestedBlock) EmptyValue() cty.Value {
37 return cty.NullVal(b.Block.ImpliedType())
39 return b.Block.EmptyValue()
41 if ty := b.Block.ImpliedType(); ty.HasDynamicTypes() {
42 return cty.EmptyTupleVal
44 return cty.ListValEmpty(ty)
47 if ty := b.Block.ImpliedType(); ty.HasDynamicTypes() {
48 return cty.EmptyObjectVal
50 return cty.MapValEmpty(ty)
53 return cty.SetValEmpty(b.Block.ImpliedType())
55 // Should never get here because the above is intended to be exhaustive,
56 // but we'll be robust and return a result nonetheless.
57 return cty.NullVal(cty.DynamicPseudoType)