Merge pull request #33902 from hashicorp/td-coerce-value-omitted-requirements

configschema: CoerceValue error for omitted attribute requirements
pull/33917/head
Jared Baker 3 years ago committed by GitHub
commit 925ccd8b26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -67,8 +67,10 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
val = in.GetAttr(name)
case attrS.Computed || attrS.Optional:
val = cty.NullVal(attrType)
default:
case attrS.Required:
return cty.UnknownVal(impliedType), path.NewErrorf("attribute %q is required", name)
default:
return cty.UnknownVal(impliedType), path.NewErrorf("attribute %q has none of required, optional, or computed set", name)
}
val, err := convert.Convert(val, attrConvType)

@ -446,6 +446,20 @@ func TestCoerceValue(t *testing.T) {
}),
``,
},
"omitted attribute requirements": {
&Block{
Attributes: map[string]*Attribute{
"foo": {
Type: cty.String,
},
},
},
cty.EmptyObjectVal,
cty.ObjectVal(map[string]cty.Value{
"foo": cty.UnknownVal(cty.String),
}),
`attribute "foo" has none of required, optional, or computed set`,
},
"dynamic value attributes": {
&Block{
BlockTypes: map[string]*NestedBlock{

Loading…
Cancel
Save