terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.88k stars 354 forks source link

Ignore module issues that are not valid expressions #1969

Closed bendrucker closed 7 months ago

bendrucker commented 7 months ago

When filtering emitted issues from child modules, ignore any issue covering an expression that cannot be parsed for references. Fixes a panic described in #1968.

EmitIssue may be called for a range that is not actually a valid Terraform expression. But TFLint just checks whether the range's source is a valid HCL expression. Something like my_block is a valid HCL expression, but it's not a valid expression in Terraform when it's a child block of a resource. Some declaration ranges (e.g., blocks with labels) are not valid HCL expressions either, but unlabeled block declarations (name, without braces) are syntactically valid expressions.

So listVarRefs must handle invalid expressions. Or callers must be able to specify that they are emitting an issue on a non-expression range, which would likely require a breaking change somewhere.

Closes https://github.com/terraform-linters/tflint/issues/1968 Closes https://github.com/terraform-linters/tflint-ruleset-opa/issues/85

ericsaboia commented 7 months ago

@bendrucker thanks for looking into this issue and fixing it so quickly! 👏