Terraform rewards a little discipline. These are the practices that keep it maintainable as a team and a codebase grow.
The practices
- Remote, locked state; separate state per environment/component
- Pin provider and module versions; commit .terraform.lock.hcl
- Keep modules small and composable; review plans in the PR
- Use workspaces or directories, never edit prod state by hand
What good looks like
A minimal AWS example with remote state and a variable.
terraform {
required_providers { aws = { source = "hashicorp/aws", version = "~> 5.0" } }
backend "s3" {
bucket = "acme-tfstate"
key = "prod/network.tfstate"
region = "eu-west-1"
}
}
variable "env" { type = string, default = "prod" }
resource "aws_s3_bucket" "assets" {
bucket = "acme-${var.env}-assets"
tags = { Environment = var.env }
}Anti-patterns to retire
- Local state on a laptop - use remote state with locking (S3+DynamoDB, TFC)
- Giant monolithic states that take minutes to plan and block the whole team
- Running apply manually without reviewing the plan
- Hardcoded secrets in .tf files instead of a secret manager
Want senior help putting Terraform to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.