do not validate Min/Max Items in CoerceValue

Due to both the nature of dynamic blocks, and the need for resources to
sometimes communicate incomplete values, we cannot validate MinItems and
MaxItems in CoerceValue.
This commit is contained in:
James Bardin 2019-08-20 09:41:17 -04:00
parent dee450cf8c
commit 731d4226d3
2 changed files with 6 additions and 14 deletions

View File

@ -8,9 +8,7 @@ import (
)
// CoerceValue attempts to force the given value to conform to the type
// implied by the receiever, while also applying the same validation and
// transformation rules that would be applied by the decoder specification
// returned by method DecoderSpec.
// implied by the receiever.
//
// This is useful in situations where a configuration must be derived from
// an already-decoded value. It is always better to decode directly from
@ -83,16 +81,8 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
if err != nil {
return cty.UnknownVal(b.ImpliedType()), err
}
case blockS.MinItems != 1 && blockS.MaxItems != 1:
if blockS.Nesting == NestingGroup {
attrs[typeName] = blockS.EmptyValue()
} else {
attrs[typeName] = cty.NullVal(blockS.ImpliedType())
}
default:
// We use the word "attribute" here because we're talking about
// the cty sense of that word rather than the HCL sense.
return cty.UnknownVal(b.ImpliedType()), path.NewErrorf("attribute %q is required", typeName)
attrs[typeName] = blockS.EmptyValue()
}
case NestingList:

View File

@ -288,8 +288,10 @@ func TestCoerceValue(t *testing.T) {
},
},
cty.EmptyObjectVal,
cty.DynamicVal,
`attribute "foo" is required`,
cty.ObjectVal(map[string]cty.Value{
"foo": cty.NullVal(cty.EmptyObject),
}),
``,
},
"unknown nested list": {
&Block{