Terraform Tip - Make Your Resource Names Unique

A good habit to get into when using Terraform is to make your resource names unique by default.

For example, if you have an AWS account that contains workloads for multiple environments, you might add the environment name to your resources.

module "ec2" {
  source  = "terraform-aws-modules/ec2-instance/aws"
  version = "5.0.0"

  name = "instance-${var.env}"
  ...
}

This is especially true for globally namespaced resources that are a pain to recreate, such as s3 buckets.

Using unique names makes it easier to spin up more infrastructure within the same account in the future.


Like what you've read?

If you're an engineering leader or developer, you should subscribe to my 80/20 DevOps Newsletter. Give me 1 minute of your day, and I'll teach you essential DevOps skills. I cover topics like Kubernetes, AWS, Infrastructure as Code, and more.

Not sure yet? Check out the archive.

Unsubscribe at any time.