Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1576
This PR adds support for dynamic blocks. TFLint already has given special consideration to dynamic blocks, but it was imperfect: blocks were not expanded, and iterators were not evaluated.
Since this PR fully expands dynamic blocks, the above example expands to:
If the
for_each
is set to an unknown value, it behaves the same as when an empty object/set is assigned. This is the same behavior as expanding resources/modules by the count/for_each meta-arguments.From a compatibility perspective, this change allows dynamic blocks to be expanded correctly, so in some cases, the block is not returned (e.g. empty object/set, unknown variables). In that case, plugin developers should use
ExpandModeNone
:Previously, differences in dynamic block schema were flattened even when the
ExpandModeNone
was set, but after this change, the actual dynamic block schema must be set.Implementation
Dynamic block expansion support uses the
hcl/ext/dynblock
like Terraform. This is an implementation ofhcl.Body
that internally duplicates blocks when returning content and wraps expressions with iterator evaluation contexts.However, there were the following problems when adopting it in TFLint:
for_each
is unknown, "unknown body" is returned.count.*
andeach.*
is included inside the dynamic block, it cannot be evaluated properly.count.*
andeach.*
when expanding thehclext.BodyContent
obtained byPartialContent
, it is not possible to include these values in the EvalContext when expanding the dynamic block.dynblock.exprWrap
is private, so we cannot efficiently bind the expression.For the reasons above, TFLint introduces the
terraform/tfhcl
package as a fork ofhcl/ext/dynblock
.Also, for the support of
count.*
andeach.*
inside dynamic blocks, expansion by meta-arguments is now the responsibility of theterraform/tfhcl
package. It internally duplicates and returns resources and modules, as an implementation ofhcl.Body
, just like a dynamic block. Since the "resource" block and the "module" block is Terraform language spec, they are implemented as theterraform/tfhcl
package, not thehclext
package.ToDo
each.*
andcount.*
in dynamic blocks