Skip to content

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

@wata727

Description

@wata727

Summary

See also #2114

Many of the overriding issues in TFLint have been fixed in #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

  • Linux
  • macOS
  • Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions