terraform-linters / tflint-ruleset-terraform

TFLint ruleset for Terraform Language
Mozilla Public License 2.0
61 stars 21 forks source link

terraform_deprecated_index fails to parse `.tf.json` #100

Closed mrwacky42 closed 1 year ago

mrwacky42 commented 1 year ago

Summary

When escaping quotes in .tf.json files, tflint has a bad day:

$ tflint
Failed to check ruleset; Failed to check `terraform_deprecated_index` rule: test.tf.json:4,28-29: Invalid character; This character is not used within the language.

This looks like the same issue as terraform-linters/tflint#694.

Command

tflint

Terraform Configuration

{
  "locals": {
    "foo": "${local.foo == \"foo\"}"
  }
}

TFLint Configuration

# No config/default.

Output

$ TFLINT_LOG=debug tflint
11:55:36 config.go:136: [INFO] Load config: .tflint.hcl
11:55:36 config.go:146: [INFO] file not found
11:55:36 config.go:154: [INFO] Load config: /Users/sharif/.tflint.hcl
11:55:36 config.go:162: [INFO] file not found
11:55:36 config.go:164: [INFO] Use default config
11:55:36 config.go:319: [INFO] The `terraform` plugin block is not found. Enable the plugin `terraform` automatically
11:55:36 option.go:70: [DEBUG] CLI Options
11:55:36 option.go:71: [DEBUG]   Module: false
11:55:36 option.go:72: [DEBUG]   Force: false
11:55:36 option.go:73: [DEBUG]   Format:
11:55:36 option.go:74: [DEBUG]   Varfiles:
11:55:36 option.go:75: [DEBUG]   Variables:
11:55:36 option.go:76: [DEBUG]   EnableRules:
11:55:36 option.go:77: [DEBUG]   DisableRules:
11:55:36 option.go:78: [DEBUG]   Only:
11:55:36 option.go:79: [DEBUG]   EnablePlugins:
11:55:36 option.go:80: [DEBUG]   IgnoreModules:
11:55:36 loader.go:38: [INFO] Initialize new loader
11:55:36 loader.go:83: [INFO] Module inspection is disabled. Building the root module without children...
11:55:36 runner.go:45: [INFO] Initialize new runner for root
11:55:36 discovery.go:33: [INFO] Plugin `terraform` is not installed, but the bundled plugin is available.
11:55:36 discovery.go:54: [INFO] Plugin `terraform` found
11:55:36 [DEBUG] go-plugin@v1.4.9/client.go:604: starting plugin: path=/usr/local/bin/tflint args=["/usr/local/bin/tflint", "--act-as-bundled-plugin"]
11:55:36 [DEBUG] go-plugin@v1.4.9/client.go:612: plugin started: path=/usr/local/bin/tflint pid=53415
11:55:36 [DEBUG] go-plugin@v1.4.9/client.go:707: waiting for RPC address: path=/usr/local/bin/tflint
11:55:36 [DEBUG] go-plugin@v1.4.9/client.go:752: using plugin: version=11
11:55:36 [DEBUG] go-plugin@v1.4.9/client.go:1046: tflint: 11:55:36 [DEBUG] go-plugin@v1.4.9/server.go:404: plugin address: network=unix address=/var/folders/5f/xtljpwms4k33n8wy6mxd5cdh0000gp/T/plugin1718084009
11:55:36 [DEBUG] host2plugin/client.go:124: starting host-side gRPC server
11:55:36 [DEBUG] go-plugin@v1.4.9/client.go:1046: tflint: 11:55:36 [ERROR] interceptor/logging.go:18: failed to gRPC request: direction=host2plugin method=/proto.RuleSet/Check err="rpc error: code = Aborted desc = Failed to check `terraform_deprecated_index` rule: test.tf.json:4,28-29: Invalid character; This character is not used within the language."
11:55:36 [DEBUG] go-plugin@v1.4.9/grpc_stdio.go:142: stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
11:55:36 [INFO]  go-plugin@v1.4.9/client.go:665: plugin process exited: path=/usr/local/bin/tflint pid=53415
11:55:36 [DEBUG] go-plugin@v1.4.9/client.go:472: plugin exited
Failed to check ruleset; Failed to check `terraform_deprecated_index` rule: test.tf.json:4,28-29: Invalid character; This character is not used within the language.

TFLint Version

0.46.1

Terraform Version

1.4.6

Operating System

bendrucker commented 1 year ago

This is resolved in https://github.com/terraform-linters/tflint-ruleset-terraform/releases/tag/v0.3.0 by https://github.com/terraform-linters/tflint-ruleset-terraform/pull/90. If you go ahead and specify that plugin version and run tflint --init you'll be set. This is a good idea anyway to enable you to use other plugins and get faster updates.

Otherwise, it's already been updated in TFLint's base branch by Dependabot as well, and so the next CLI release will bundle 0.3.0 or later.

bendrucker commented 1 year ago

See also #101, prompted by this I noticed that there were false negatives for JSON files. My first step there was adding test coverage against valid cases, including one comparable to yours, which confirmed they are already fixed. But then I was also able to restore detection of legacy syntax too.

mrwacky42 commented 1 year ago

Derp! I didn't bother to realize that there's a separate plugin for HCL itself. Thanks.

bendrucker commented 1 year ago

All good, it's bundled, so you don't have to notice out of the box. But like I said, a good idea anyway, and will get you patched up immediately.