Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow empty dynamic blocks with ConfigModeAttr #21549

Merged
merged 1 commit into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lang/blocktoattr/fixup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
9 changes: 5 additions & 4 deletions lang/blocktoattr/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
}
}
Expand Down