Merge pull request #21549 from hashicorp/jbardin/empty-dynamic-attr

allow empty dynamic blocks with ConfigModeAttr
This commit is contained in:
James Bardin 2019-06-01 12:01:49 -05:00 committed by GitHub
commit ebc2e5fb56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -196,6 +196,20 @@ dynamic "foo" {
}),
}),
},
"dynamic block with empty iterator": {
src: `
dynamic "foo" {
for_each = []
content {
bar = foo.value
}
}
`,
schema: fooSchema,
want: cty.ObjectVal(map[string]cty.Value{
"foo": cty.NullVal(fooSchema.Attributes["foo"].Type),
}),
},
"both attribute and block syntax": {
src: `
foo = []

View File

@ -55,10 +55,11 @@ func effectiveSchema(given *hcl.BodySchema, body hcl.Body, ambiguousNames map[st
},
}
content, _, _ = body.PartialContent(&probeSchema)
if len(content.Blocks) > 0 {
// No attribute present and at least one block present, so
// we'll need to rewrite this one as a block for a successful
// result.
if len(content.Blocks) > 0 || dynamicExpanded {
// A dynamic block with an empty iterator returns nothing.
// If there's no attribute and we have either a block or a
// dynamic expansion, we need to rewrite this one as a
// block for a successful result.
appearsAsBlock[name] = struct{}{}
}
}