If a dynamic block (in the HCL dynamic block extension sense) has an
unknown value for its for_each argument, it gets expanded to a single
placeholder block with all of its attributes set to a unknown values.
We can use this as part of a heuristic to relax our object compatibility
checks for situations where the plan included an object that appears to
be (but isn't necessarily) such a placeholder, allowing for the fact that
the one placeholder block could be replaced with zero or more real blocks
once the for_each value is known.
Previously our heuristic was too strict: it would match only if the only
block present was a dynamic placeholder. In practice, users may mix
dynamic blocks with static blocks of the same type, so we need to be more
liberal to avoid generating incorrect incompatibility errors in such
cases.
fooBarBlockDynamicPlaceholder,// the presence of this disables some of our checks
}),
}),
cty.ObjectVal(map[string]cty.Value{
"key":cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"foo":cty.StringVal("hello"),
}),
cty.ObjectVal(map[string]cty.Value{
"foo":cty.StringVal("world"),
}),
}),
}),
nil,// a single block whose attrs are all unknown is allowed to expand into multiple, because that's how dynamic blocks behave when for_each is unknown
},
{
&configschema.Block{
BlockTypes:map[string]*configschema.NestedBlock{
"key":{
Nesting:configschema.NestingList,
Block:schemaWithFooBar,
},
},
},
cty.ObjectVal(map[string]cty.Value{
"key":cty.ListVal([]cty.Value{
fooBarBlockValue,// the presence of one static block does not negate that the following element looks like a dynamic placeholder
fooBarBlockDynamicPlaceholder,// the presence of this disables some of our checks
}),
}),
cty.ObjectVal(map[string]cty.Value{
"key":cty.ListVal([]cty.Value{
fooBlockValue,
cty.ObjectVal(map[string]cty.Value{
"foo":cty.StringVal("hello"),
}),
cty.ObjectVal(map[string]cty.Value{
"foo":cty.StringVal("world"),
}),
}),
}),
nil,// as above, the presence of a block whose attrs are all unknown indicates dynamic block expansion, so our usual count checks don't apply