Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider_missing_default_tags does not work with dynamic tags #850

Closed
JeremieDoctrine opened this issue Mar 26, 2025 · 8 comments · Fixed by #851
Closed

provider_missing_default_tags does not work with dynamic tags #850

JeremieDoctrine opened this issue Mar 26, 2025 · 8 comments · Fixed by #851

Comments

@JeremieDoctrine
Copy link

JeremieDoctrine commented Mar 26, 2025

We imports tags from a module.

And apply them this way :

provider "aws" {
  region = "eu-central-1"
  default_tags {
    tags = module.commons.tags
  }  
}

When trying to add the rule :

rule "aws_provider_missing_default_tags" {
    enabled = true
    tags = ["terraform_stack", "terraform_ci_deployed"]
}

tflint fails saying that theses tags are not set.

❯ tflint --config=./.tflint.hcl --recursive --minimum-failure-severity=notice && echo "succcess"
1 issue(s) found:

Notice: The provider is missing the following tags: "terraform_ci_deployed", "terraform_stack". (aws_provider_missing_default_tags)

  on providers.tf line 27:
  27:     tags = module.commons.tags

Reference: https://github.com/terraform-linters/tflint-ruleset-aws/blob/v0.33.0/docs/rules/aws_provider_missing_default_tags.md

If I manually set the tagsm it runs successfuly :

provider "aws" {
  region = "eu-central-1"
  default_tags {
    tags = {
      terraform_ci_deployed = "xoxo"
      terraform_stack       = "fdsfds"
    }
  }
}
❯ tflint --config=./.tflint.hcl --recursive --minimum-failure-severity=notice && echo "succcess"
succcess

I'm not sure if it is expected or not?

@bendrucker
Copy link
Member

Well what's the module definition?

@JeremieDoctrine
Copy link
Author

@bendrucker The module outputs something like that

output "tags" {
  value = merge(
    {
      terraform_stack       = var.stack
      terraform_ci_deployed = var.ci_deployed
    },
    var.workspace != "" ? { terraform_workspace = var.workspace } : {},
    var.contains_user_data ? { VantaContainsUserData = "True" } : {},
  )
}

@bendrucker
Copy link
Member

What about the module call? Are all of those variables set?

Regardless, the definite bug here would be that required tags aren't suppressed entirely if the provider has default tags that are unknown.

When that happens, the rule should assume those default tags could be anything and return early without any further checks.

@JeremieDoctrine
Copy link
Author

JeremieDoctrine commented Mar 26, 2025

The module is called this way :

module "commons" {
  source      = "../commons?ref=commons-v1"
  stack       = "xxxx"
  ci_deployed = true
}

And it does not have default values:

variable "stack" {
  description = "macro level infra structure component (eg: vpc, main-db...)"
  type        = string
}
variable "ci_deployed" {
  description = "whether or not the stack is automatically deployed"
  type        = bool
}

It does not have default values but the values are set.

@bendrucker
Copy link
Member

And var.contains_user_data and var.workspace have defaults?

@JeremieDoctrine
Copy link
Author

Yes

variable "stack" {
  description = "macro level infra structure component (eg: vpc, main-db...)"
  type        = string
}
variable "workspace" {
  description = "environment (eg: production, development...)"
  type        = string
  default     = ""
}
variable "ci_deployed" {
  description = "whether or not the stack is automatically deployed"
  type        = bool
}
variable "contains_user_data" {
  description = "insert the reserved tag VantaContainsUserData"
  type        = bool
  default     = false
}

@bendrucker
Copy link
Member

Hmm, so in theory merge should be able to determine a known type/value. But while in theory it's possible to statically evaluate these module outputs, it's not actually supported at the moment:

terraform-linters/tflint#2076

That said, #851 will fix the false positive issue that you're seeing.

@bendrucker bendrucker changed the title AWS aws_provider_missing_default_tags does not work with dynamic tags provider_missing_default_tags does not work with dynamic tags Mar 26, 2025
@JeremieDoctrine
Copy link
Author

Oh I see. Thanks a lot for finding the issue with tflint directly I didn't see it. Thanks again for providing a fix for the false positive 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants