Terraform

Describe how you manage state file(s) when you have multiple environments (e.g. development, staging and production)

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

Probably no right or wrong answer here, but it seems, based on different source, that the overall preferred way is to have a dedicated state file per environment.

Common patterns:

  • Separate backend configurations per environment (different S3 prefixes or even different buckets and DynamoDB tables).

  • Distinct workspaces or directories when you need isolated state plus different credentials.

  • Terraform Cloud organizations/workspaces mapped to environments with role-based access control.