Terraform Best Practices

Chapter 1 · Practice 3 of 4

Name resources with descriptive nouns, without repeating the type

From Structure and style

Why it matters

A resource address already contains its type, so aws_instance.web_server_instance says "instance" twice. The style guide recommends descriptive nouns with underscores, and not repeating the resource type in the name.

AvoidPrefer
aws_s3_bucket.s3_bucketaws_s3_bucket.invoices
aws_instance.web-serveraws_instance.web
aws_security_group.sg1aws_security_group.database

Inside a block, keep a predictable order: count or for_each first, then plain arguments, then nested blocks, then lifecycle, then depends_on. The same order everywhere makes diffs smaller and reviews faster.

Avoid

  • Hyphens in resource names: use underscores
  • Generic names like this, main or sg1 in root modules