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

ignore lang.ReferencesInExpr errors when walking all expressions #759

Merged
merged 2 commits into from May 19, 2020

Conversation

bendrucker
Copy link
Member

@bendrucker bendrucker commented May 19, 2020

When visiting all expressions, we might encounter special attributes/blocks, where normal reference rules no longer apply:

https://www.terraform.io/docs/configuration/resources.html#meta-arguments

This currently returns an error for the unused_declarations and workspace_remote rules:

Error: Invalid reference: A reference to a resource type must be followed by at least one attribute access, specifying the resource name.

Detecting these attributes seems too brittle/awkward, so simply exiting if an expression cannot be evaluated for references seems like the best fix

Copy link
Member

@wata727 wata727 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm... Good catch, @bendrucker

Terraform doesn't seem to have this problem because it treats meta-arguments specially.
https://github.com/hashicorp/terraform/blob/v0.12.25/configs/resource.go#L117-L144

Ideally, I feel like we need lang.ReferencesInExpr that can handle non-evaluable expressions, but it certainly seems difficult. Or maybe we need a WalkExpressions that ignores the meta-arguments.

I leave only one comment, but at this point, the basic policy seems to be fine.

@bendrucker
Copy link
Member Author

Totally, I'm open to addressing this in WalkExpressions. Not sure we can deal with it once we're at the expression level, since we need to know that we're in a special meta-argument.

@bendrucker
Copy link
Member Author

Wanted to get this fixed ASAP but I can try to follow up so we don't have to ignore these errors in rules.

@bendrucker bendrucker requested a review from wata727 May 19, 2020 15:33
@wata727 wata727 merged commit 7a8bef1 into terraform-linters:master May 19, 2020
Copy link
Member

@wata727 wata727 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great 👍

@bendrucker bendrucker deleted the ignore-lang-expr-errors branch May 19, 2020 16:35
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.

None yet

2 participants