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

rules: Use WalkResources to avoid a bug in JSON syntax #130

Merged
merged 1 commit into from
Nov 1, 2021

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Oct 31, 2021

Closes #129

When extracting blocks whose body is an array with the WalkResourceBlocks API, there may be a problem that parsing fails in JSON syntax.

This is due to a problem with the hack that gets the code snippet of hcl.Body on transfer from the TFLint host. MissingItemRange properly corresponds to the closing brace when the target is an object, but corresponds to the opening brace when it is an array.
https://github.com/terraform-linters/tflint/blob/v0.33.1/tflint/terraform.go#L107-L108
https://github.com/hashicorp/hcl/blob/v2.10.1/json/structure.go#L224

Since json.body is unexported, fixing this problem is not easy. As a workaround, this PR rewrites using the WalkResources API. In this API, the target body is always an object, so this extraction is successful.

The essential fix is to change the transferring way of this body. This is already being addressed by reimplementing the plugin system.
terraform-linters/tflint-plugin-sdk#89

@wata727 wata727 merged commit 618c5d6 into master Nov 1, 2021
@wata727 wata727 deleted the use_walk_resources branch November 1, 2021 16:40
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.

Unexpected JSON parsing error
1 participant