I’d like to set “Environment = local.environment_name” in resources without having to repeat lots of code. Default tags seemed to be the correct solution, and I was wondering if anyone knows of a better way to set a dynamic tag.
provider "aws" {
default_tags {
tags = {
Environment = "Default"
Owner = "my_department"
}
}
}
resource "aws_ssm_parameter" "tag-tester-parameter" {
name = "/test/tag-tester-parameter"
type = "StringList"
value = "parameter1, parameter2"
overwrite = false
tags = {
Name = "/test/tag-tester-parameter"
Environment = local.environment_name
}
}
Those 2 together will correctly set the “Environment” tag to “Dev”.
But I don’t want to repeat myself across hundreds of resources, and any changes needed to that tag would require me updating all those hundreds of resources.
Is there a way to set Environment to Dev without repeating myself across resources?