Terraform interview question · Most asked

Workspaces, separate state files, or separate directories: how do you manage multiple environments?

Summary

Terraform CLI workspaces give one configuration several state files (dev, staging, prod) selected at runtime, which is convenient but makes environments look identical and easy to confuse. Many teams prefer separate root modules or directories per environment (each with its own backend key and variables) that call shared modules, or tools such as Terragrunt.

Longer Answer

Separate directories make differences explicit (prod has more replicas, different instance sizes), allow different provider credentials and approval rules per environment, and reduce the risk of applying to prod by mistake. Workspaces suit short-lived copies of the same stack (feature environments). HCP Terraform "workspaces" are a different concept: each is effectively a separate state with its own variables and permissions.

Key Points

  • CLI workspaces: one config, many states.
  • Separate root modules per environment are explicit.
  • Different credentials and approvals per environment.
  • HCP workspaces differ from CLI workspaces.

More most-asked Terraform questions

← All Terraform questions