tflint: Add WalkExpressions function #181
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.
This PR adds
WalkExpressions
function as a new runner API. This function is a wrapper that applies a callback function to allhcl.Expression
retrieved usingGetFiles()
.This function is useful for detecting all variable references contained within expressions, or forbidding certain resource references entirely. The argument can be a simple callback function, or any struct that satisfies the
ExprWalker
interface. If you pass a callback function, it will be invoked for every expression.The internal implementation uses
hclsyntax.Walk
. So for example a callback will be called 3 times to"${var.foo}-${var.bar}"
for itself,var.foo
andvar.bar
. On the other hand, note that it behaves differently for JSON syntax. A callback is not called forvar.foo
andvar.bar
. Nor does it recursively traverse maps or objects. This is an interface issue for the JSON syntax. Please see hashicorp/hcl#543 for details.