From 731d4226d3816d9ae67bbe4fa0db4243500a2850 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 20 Aug 2019 09:41:17 -0400 Subject: [PATCH] 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. --- configs/configschema/coerce_value.go | 14 ++------------ configs/configschema/coerce_value_test.go | 6 ++++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/configs/configschema/coerce_value.go b/configs/configschema/coerce_value.go index 23a48e1be..41a533745 100644 --- a/configs/configschema/coerce_value.go +++ b/configs/configschema/coerce_value.go @@ -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: diff --git a/configs/configschema/coerce_value_test.go b/configs/configschema/coerce_value_test.go index 084107878..974dfdd35 100644 --- a/configs/configschema/coerce_value_test.go +++ b/configs/configschema/coerce_value_test.go @@ -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{