mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #21549 from hashicorp/jbardin/empty-dynamic-attr
allow empty dynamic blocks with ConfigModeAttr
This commit is contained in:
commit
ebc2e5fb56
@ -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": {
|
"both attribute and block syntax": {
|
||||||
src: `
|
src: `
|
||||||
foo = []
|
foo = []
|
||||||
|
@ -55,10 +55,11 @@ func effectiveSchema(given *hcl.BodySchema, body hcl.Body, ambiguousNames map[st
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
content, _, _ = body.PartialContent(&probeSchema)
|
content, _, _ = body.PartialContent(&probeSchema)
|
||||||
if len(content.Blocks) > 0 {
|
if len(content.Blocks) > 0 || dynamicExpanded {
|
||||||
// No attribute present and at least one block present, so
|
// A dynamic block with an empty iterator returns nothing.
|
||||||
// we'll need to rewrite this one as a block for a successful
|
// If there's no attribute and we have either a block or a
|
||||||
// result.
|
// dynamic expansion, we need to rewrite this one as a
|
||||||
|
// block for a successful result.
|
||||||
appearsAsBlock[name] = struct{}{}
|
appearsAsBlock[name] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user