How do you manage multiple environments (dev/staging/prod) in Terraform? Workspaces vs. directory structure.
Two main approaches:
Terraform Workspaces: Use the same code but switch workspace to change state. Simple, but the same code runs for all environments — hard to have different variable values per environment. Suitable for simple differences.
Separate Directories (recommended): Each environment has its own directory with its own terraform.tfvars and remote state. This is explicit, auditable, and allows environments to diverge safely.
environments/
dev/
main.tf → calls shared module
terraform.tfvars
staging/
main.tf
terraform.tfvars
prod/
main.tf
terraform.tfvars
modules/
vpc/
eks/