Terraform: standardize AWS tags
I love problems that force me to learn something "new" to solve it!
When I started to use Terraform a week ago, one of the problems that I wanted to solve was to add unique Name tags to my AWS resources along with a set of standard tags. This is how I resolved it.
locals {
common_tags = {
company = var.company
project = "${var.company}-${var.project}"
billing_code = var.billing_code
}
}
2. Add the Name tag in the resource
# 1.VPC
resource "aws_vpc" "security" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
tags = merge(local.common_tags, { Name = "Security VPC" })
}
This helped with two things.
2. Normally I am lazy when I add resources in Console to add the tags! But no I just have to add them to my code as I need them. Any new new "terraform apply" only updates the deployment.