rules: Use WalkResources to avoid a bug in JSON syntax #130
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.
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 theWalkResources
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