Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tflint: Add WalkExpressions function #181

Merged
merged 1 commit into from
Aug 21, 2022
Merged

tflint: Add WalkExpressions function #181

merged 1 commit into from
Aug 21, 2022

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Aug 21, 2022

This PR adds WalkExpressions function as a new runner API. This function is a wrapper that applies a callback function to all hcl.Expression retrieved using GetFiles().

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 and var.bar. On the other hand, note that it behaves differently for JSON syntax. A callback is not called for var.foo and var.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.

@wata727 wata727 marked this pull request as ready for review August 21, 2022 13:01
@wata727 wata727 merged commit 3b6ea1a into master Aug 21, 2022
@wata727 wata727 deleted the add_expr_walker branch August 21, 2022 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant