terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.86k stars 353 forks source link

"Invalid character" when using interpolation within directive #1572

Closed nonmanager closed 1 year ago

nonmanager commented 1 year ago

Introduction

When a simple directive is written, such as in this example, interpolation cannot be used. Using the $ character within the scope of the directive causes the linter to fail with an error.

Sample code (tested with Terraform 1.2.9):

terraform {
  required_version = ">= 1.2.9"
}

variable "myvar" {
  type    = string
  default = "dear"
}

output "example" {
  value = "Hello, %{if var.myvar != "cruel"}${var.myvar}%{endif} world!"
}

Terraform happily accepts this:

Outputs:

example = "Hello, dear world!"

Expected Behavior

Running tflint should succeed. It is what happens with v0.41.0.

Actual behavior

Running tflint (v0.42.0 and v0.42.1) fails with the following error:

Failed to check ruleset; Failed to check `terraform_deprecated_index` rule: main.tf:11,50-51: Invalid character; This character is not used within the language.

Step to Reproduce

Run tflint on the code given above.

bendrucker commented 1 year ago

Definitely a bug. Duplicate of terraform-linters/tflint-ruleset-terraform#42.