terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.98k stars 357 forks source link

for_each/count meta-arguments are not overridden correctly #2151

Open wata727 opened 3 weeks ago

wata727 commented 3 weeks ago

Summary

See also https://github.com/terraform-linters/tflint/issues/2114

Many of the overriding issues in TFLint have been fixed in https://github.com/terraform-linters/tflint/pull/2124, but there are still issues with overriding meta arguments. In Terraform, meta arguments are overridden and then resources are expanded, but in TFLint, they are overridden after expansion, so if the original and override meta arguments are different, the override expansion cannot be followed.

Command

tflint

Terraform Configuration

# main.tf
resource "aws_instance" "main" {
  instance_type = "t2.micro"
}

# main_override.tf
resource "aws_instance" "main" {
  count = 2

  instance_type = "t${count.index + 1}.invalid"
}

TFLint Configuration

plugin "terraform" {
  enabled = false
}

plugin "aws" {
  enabled = true
  version = "0.34.0"
  source  = "github.com/terraform-linters/tflint-ruleset-aws"
}

Output

1 issue(s) found:

Error: "t2.invalid" is an invalid value as instance_type (aws_instance_invalid_type)

  on main_override.tf line 4:
   4:   instance_type = "t${count.index + 1}.invalid"

Issues should be reported for two resources, but only one is reported.

TFLint Version

0.53.0

Terraform Version

1.9.8

Operating System