CoerceValue should insert Null for unset attrs
This matches the decoder spec, where a value unset in the configuration is always Null.
This commit is contained in:
parent
50e099ad10
commit
8f295fcb22
|
@ -58,9 +58,7 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
|
|||
switch {
|
||||
case ty.HasAttribute(name):
|
||||
val = in.GetAttr(name)
|
||||
case attrS.Computed:
|
||||
val = cty.UnknownVal(attrS.Type)
|
||||
case attrS.Optional:
|
||||
case attrS.Computed || attrS.Optional:
|
||||
val = cty.NullVal(attrS.Type)
|
||||
default:
|
||||
return cty.UnknownVal(b.ImpliedType()), path.NewErrorf("attribute %q is required", name)
|
||||
|
|
|
@ -342,6 +342,22 @@ func TestCoerceValue(t *testing.T) {
|
|||
cty.DynamicVal,
|
||||
`.foo: number required`,
|
||||
},
|
||||
"unset computed value": {
|
||||
&Block{
|
||||
Attributes: map[string]*Attribute{
|
||||
"foo": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.ObjectVal(map[string]cty.Value{}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.NullVal(cty.String),
|
||||
}),
|
||||
``,
|
||||
},
|
||||
}
|
||||
|
||||
for name, test := range tests {
|
||||
|
|
Loading…
Reference in New Issue