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

Feature Request: Ability to specify default tags at provider level #1478

Open
gavinclarkeuk opened this issue Jun 28, 2022 · 6 comments
Open

Comments

@gavinclarkeuk
Copy link

Terraform Version

1.2.1 (although this is a provider request)

Affected Resource(s)

All resource types that support tags

Details

It would be great if it were possible to define a set of default tags at the provider level, that automatically get applied to all resources managed by a given provider instance. This feature is inspired by a similar feature in the AWS provider.

This would change the provider declaration to look something like this:

provider "datadog" {
  api_key = var.datadog_api_key
  app_key = var.datadog_app_key
  
  default_tags = ["foo:bar", "team:fooBar"]
}

Similar to the AWS provider, if tags are also defined on a specific resource they would be combined with the default tags, overriding any default tags with the same key.

@kderck
Copy link

kderck commented Jul 21, 2022

This would be great. We use Terragrunt which creates the Provider at runtime where we interpolate the tags from the directory structure following a Convention over Configuration approach. We include this file once in every child terragrunt.hcl

locals {  
  tags = { 
    service       : basename(get_terragrunt_dir())  
    env           : basename(dirname(get_terragrunt_dir()))
    region        : basename(dirname(dirname(get_terragrunt_dir())))
    created_by    : "terraform"
    version       : get_env("GITHUB_RUN_ID", "Manual") 
    modified_by   : get_platform() == "windows" ? get_env("USERNAME") : get_env("USER", "unknown")
  }
}

generate "provider" {
  path      = "provider.tf"
  if_exists = "overwrite_terragrunt"
  contents  = <<EOF
provider "aws" {
  region  = "${local.tags.region}"
  default_tags {
    tags = {
      service       : "${local.tags.service}"
      env           : "${local.tags.env}"
      region        : "${local.tags.region}"
      created_by    : "${local.tags.created_by}"
      version       : "${local.tags.version}"
      modified_by   : "${local.tags.modified_by}"
    }
  }
}
EOF
}

@nrowegt
Copy link

nrowegt commented Jan 23, 2024

+1 for this. It would be immensely helpful.

@benriou
Copy link

benriou commented Apr 24, 2024

+1 too.

@ahached
Copy link

ahached commented May 30, 2024

It will be really helpfull to have this feature, it make it easier to enforce some defaults tags on all the datadog ressources like aws.

@haidaraM
Copy link

+1 for this as well. However, this PR #2486 seems to consider tags as key-values instead of lists. Shouldn't the default tags be a list to match the tags set at the resources level?

@matthewmrichter
Copy link

Also, the nesting of default_tags { tags ={} } feels redundant.

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

No branches or pull requests

7 participants