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 workaround to get the range of configs.mergeBody #1019

Merged
merged 1 commit into from
Jan 1, 2021

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Dec 30, 2020

tflint.HCLBodyRange is used to get the start position of the range in order to send hcl.Body to plugins. This implementation uses the filename extension to determine if it's native or JSON syntax, and gets each one in a rather unintuitive way.

However, there is a big problem with this assumption. First, hclsyntax.Body is not the only struct that satisfies hcl.Body in the .tf file. This method receives configs.mergeBody if resources were overridden.

Handling merged bodies is very difficult with the current implementation. First, tflint.HCLBodyRange should not return a single range, as it consists of multiple files and ranges. This PR changes the implementation to return an empty range for avoiding panic

I understand that this is not reasonable. However, while it is possible in native syntax to return some warning instead of returning an empty range, JSON syntax cannot even determine if it is merged body because the struct is private. I believe this change is the best way with minimal changes.

In the future, I plan to solve this inconvenience by changing the plugin interface. See also terraform-linters/tflint-plugin-sdk#89

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

1 participant