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 {
|
switch {
|
||||||
case ty.HasAttribute(name):
|
case ty.HasAttribute(name):
|
||||||
val = in.GetAttr(name)
|
val = in.GetAttr(name)
|
||||||
case attrS.Computed:
|
case attrS.Computed || attrS.Optional:
|
||||||
val = cty.UnknownVal(attrS.Type)
|
|
||||||
case attrS.Optional:
|
|
||||||
val = cty.NullVal(attrS.Type)
|
val = cty.NullVal(attrS.Type)
|
||||||
default:
|
default:
|
||||||
return cty.UnknownVal(b.ImpliedType()), path.NewErrorf("attribute %q is required", name)
|
return cty.UnknownVal(b.ImpliedType()), path.NewErrorf("attribute %q is required", name)
|
||||||
|
|
|
@ -342,6 +342,22 @@ func TestCoerceValue(t *testing.T) {
|
||||||
cty.DynamicVal,
|
cty.DynamicVal,
|
||||||
`.foo: number required`,
|
`.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 {
|
for name, test := range tests {
|
||||||
|
|
Loading…
Reference in New Issue