terraformrules: Walk map/list expressions deeply #1432
Merged
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 #1257
Previously,
WalkExpressions
visited expressions based on the structure parsed by Terraform's internal API. Therefore, when the expression is nested in an expression such as map or list, there is an issue that it is not possible to walk the nested expression correctly.This PR changes to use the HCL's native
Walk
function instead of the structure parsed by Terraform's internal API to walk expressions deeply. Note that this change will inspect the overridden configuration. This is because all files are inspected, regardless of Terraform semantics.Also, there are some caveats when walking the JSON expressions. Unlike the native HCL syntax, the JSON syntax does not provide a
Walk
function, so we cannot walk for an expression in an expression. This has room for improvement, but at this point, it only walks top-level expressions. Therefore, it is possible that a wider range than the original expression range will be reported.