terraform-linters / tflint-ruleset-aws

TFLint ruleset for terraform-provider-aws
Mozilla Public License 2.0
327 stars 71 forks source link

rule `aws_resource_missing_tags` does not work with resources with count meta argument #467

Closed evairmarinho closed 1 year ago

evairmarinho commented 1 year ago

piece of main.tf

resource "aws_iam_policy" "s3_read" {
  count       = var.create_bucket ? 1 : 0
  name        = "policy-s3-read-${aws_s3_bucket.this[0].id}"
  path        = "/"
  description = "Policy para leitura de bucket"

  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action = [
          "s3:GetObject",
          "s3:ListBucket"
        ]
        Effect = "Allow"
        Resource = [
          aws_s3_bucket.this[0].arn,
          "${aws_s3_bucket.this[0].arn}/*"
        ]
      },
    ]
  })
}

.tflint.hcl core configuration

config {
  disabled_by_default = true
}

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

rule "aws_resource_missing_tags" {
    enabled = true
    tags = ["Name"]
}

versions

TFLint version 0.43.0
+ ruleset.terraform (0.2.1-bundled)
+ ruleset.aws (0.21.1)
bendrucker commented 1 year ago

Missing info: variable definition. Please make the config runnable by eliminating any implicit dependencies so we can be certain we understand the input and behavior.

evairmarinho commented 1 year ago

@bendrucker , tkanks for support. The create_bucket variable had the default value false. Leaving true, and running tflint again, the rule worked. Using this rule in module, i see this as a gap. What do you think?

bendrucker commented 1 year ago

This isn't specific to this rule. TFLint skips resources where count = 0. If there's a default that's the assumed value if none is provided. If you want to cover that case, set the var to true in your TFLint runs.

evairmarinho commented 1 year ago

Thanks for workaround @bendrucker . I will colse this issue.