A Terraform module to apply AWS tagging in a standardized way.
Tagging resources at AWS sometimes is a feature put aside compared to other duties to be carried out. But tagging not only makes your resources easier to understand, but also allow you to make much better automation by making usage of the metadata or help you to have better cost reports.
This Terraform modules tries to applies best practices and make it easier to tagging in a standardized way.
- Make uses of a prefix to build all tags keys.
- Exports tags as outputs for usage.
- Flexible
Name
tag generation. - Validation of input variables.
- Generate tags as a
map
and also tags (asg_tags
) that can be consumed by Auto Scaling Groups. - DRY.
Terraform v0.14 or higher.
git clone
this repository, and edit thevariables.tf
andoutputs.tf
files as required to implement your own tags.- Import the module into your other resource modules.
- Pass all required input variables.
- Use the module outputs (
tags
andasg_tags
).
For an EC2 instance module:
module "common_tags" {
source = "../../..modules/tags"
environment = var.environment
project_name = var.project_name
owner = var.my_team
add_name_tag = false
tag_prefix = var.my_company
repository = var.my_git_repo
}
# latter
resource "aws_instance" "jenkins" {
ami = data.aws_ami.jenkins.id
instance_type = "t2.small"
key_name = var.key_pair_name
tags = merge(module.common_tags.tags, {Name = "LittleJenkins"})
}
One can use those variables combined in order to enable/disable adding a Name
tag on the resource.
- if
name
is informed, aName
tag with the informed value will be added to the resource only ifadd_name_tag
istrue
. - if
name
is not informed, theproject_name
value will be used instead, ifadd_name_tag
istrue
, with theName
tag.