-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[Enhancement]: default_tags from environment variables #33255
Comments
Community NoteVoting for Prioritization
Volunteering to Work on This Issue
|
Hey @jtdoepke 👋 Thank you for taking the time to raise this, and for opening a pull request to implement it! I'll let the team go through their normal review process, but wanted to mention a workaround in the meantime. Terraform has the capability of loading values for variables by reading environment variables prefixed with provider "aws" {
default_tags {
# with merge(), if the same key exists in both maps, the later one takes precedence
tags = merge(var.default_tags, var.additional_default_tags)
}
}
variable "default_tags" {
description = "A map where the key is Environment and the value is the environment. Should be read from the environment and not passed directly."
type = map
default = null
}
variable "additional_default_tags" {
description = "A map of tag names to tag values"
type = map
default = null
}
resource "aws_s3_bucket" "test" {
bucket = "test"
}
output "tags" {
value = aws_s3_bucket.test.tags_all
} With this additional_default_tags = { Terraform = true, Environment = "prod" } The following output occurs (note the override of $ TF_VAR_default_tags='{ Environment = "dev" }' terraform plan
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_s3_bucket.test will be created
+ resource "aws_s3_bucket" "test" {
+ acceleration_status = (known after apply)
+ acl = (known after apply)
+ arn = (known after apply)
+ bucket = "test"
+ bucket_domain_name = (known after apply)
+ bucket_prefix = (known after apply)
+ bucket_regional_domain_name = (known after apply)
+ force_destroy = false
+ hosted_zone_id = (known after apply)
+ id = (known after apply)
+ object_lock_enabled = (known after apply)
+ policy = (known after apply)
+ region = (known after apply)
+ request_payer = (known after apply)
+ tags_all = {
+ "Environment" = "prod"
+ "Terraform" = "true"
}
+ website_domain = (known after apply)
+ website_endpoint = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ tags = {
+ Environment = "prod"
+ Terraform = "true"
} |
Yep, that's a totally valid way to do this. Our usecase here is that we want to add a common set of default_tags for cost control ( My company has a lot of teams distributed globally that are using Terraform relatively independently. I think that this feature will also save us time. If any of those teams forget to implement the above workaround pattern in their own TF, we won't have go bother them to change it. |
Just to add that this would give an additional benefit whereby you don't have to define:
...in every calling module to ensure it gets passed through to wherever the provider block is defined. |
Warning This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them. Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed. |
This functionality has been released in v5.62.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Description
I would like to be able to configure the
default_tags
of the AWS provider using environment variables.This would be useful, for example, in Terraform Cloud/Enterprise. If I have a bunch of workspaces organized under a project, I could attach a variable set to the project with an environment variable that would configure a tag like
Owner=my-team
across the entire set of AWS resources under that project.Affected Resource(s) and/or Data Source(s)
Potential Terraform Configuration
References
Pull request to implement this change: #33339
Would you like to implement a fix?
Yes
The text was updated successfully, but these errors were encountered: