Skip to content

Commit

Permalink
Merge pull request #22478 from hashicorp/jbardin/coerce-value
Browse files Browse the repository at this point in the history
don't validate Min/Max block vals in CoerceValue
  • Loading branch information
jbardin authored Aug 16, 2019
2 parents 1fecbbd + 554ceda commit 3e03213
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
24 changes: 2 additions & 22 deletions configs/configschema/coerce_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
}
l := coll.LengthInt()

// Assume that if there are unknowns this could have come from
// a dynamic block, and we can't validate MinItems yet.
if l < blockS.MinItems && coll.IsWhollyKnown() {
return cty.UnknownVal(b.ImpliedType()), path.NewErrorf("insufficient items for attribute %q; must have at least %d", typeName, blockS.MinItems)
}
if l > blockS.MaxItems && blockS.MaxItems > 0 {
return cty.UnknownVal(b.ImpliedType()), path.NewErrorf("too many items for attribute %q; cannot have more than %d", typeName, blockS.MaxItems)
}
if l == 0 {
attrs[typeName] = cty.ListValEmpty(blockS.ImpliedType())
continue
Expand All @@ -140,10 +132,8 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
}
}
attrs[typeName] = cty.ListVal(elems)
case blockS.MinItems == 0:
attrs[typeName] = cty.ListValEmpty(blockS.ImpliedType())
default:
return cty.UnknownVal(b.ImpliedType()), path.NewErrorf("attribute %q is required", typeName)
attrs[typeName] = cty.ListValEmpty(blockS.ImpliedType())
}

case NestingSet:
Expand All @@ -165,14 +155,6 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
}
l := coll.LengthInt()

// Assume that if there are unknowns this could have come from
// a dynamic block, and we can't validate MinItems yet.
if l < blockS.MinItems && coll.IsWhollyKnown() {
return cty.UnknownVal(b.ImpliedType()), path.NewErrorf("insufficient items for attribute %q; must have at least %d", typeName, blockS.MinItems)
}
if l > blockS.MaxItems && blockS.MaxItems > 0 {
return cty.UnknownVal(b.ImpliedType()), path.NewErrorf("too many items for attribute %q; cannot have more than %d", typeName, blockS.MaxItems)
}
if l == 0 {
attrs[typeName] = cty.SetValEmpty(blockS.ImpliedType())
continue
Expand All @@ -191,10 +173,8 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
}
}
attrs[typeName] = cty.SetVal(elems)
case blockS.MinItems == 0:
attrs[typeName] = cty.SetValEmpty(blockS.ImpliedType())
default:
return cty.UnknownVal(b.ImpliedType()), path.NewErrorf("attribute %q is required", typeName)
attrs[typeName] = cty.SetValEmpty(blockS.ImpliedType())
}

case NestingMap:
Expand Down
28 changes: 0 additions & 28 deletions configs/configschema/coerce_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,34 +291,6 @@ func TestCoerceValue(t *testing.T) {
cty.DynamicVal,
`attribute "foo" is required`,
},
"missing required list block": {
&Block{
BlockTypes: map[string]*NestedBlock{
"foo": {
Block: Block{},
Nesting: NestingList,
MinItems: 1,
},
},
},
cty.EmptyObjectVal,
cty.DynamicVal,
`attribute "foo" is required`,
},
"missing required set block": {
&Block{
BlockTypes: map[string]*NestedBlock{
"foo": {
Block: Block{},
Nesting: NestingList,
MinItems: 1,
},
},
},
cty.EmptyObjectVal,
cty.DynamicVal,
`attribute "foo" is required`,
},
"unknown nested list": {
&Block{
Attributes: map[string]*Attribute{
Expand Down

0 comments on commit 3e03213

Please sign in to comment.