How do you manage multiple environments (dev, staging, prod) in Terraform?
What they are really testing: Whether you know the options (workspaces vs directory/state per environment) and the trade-off, and that prod is usually best isolated with its own state and backend.
A real interview question
How do you manage multiple environments (dev, staging, prod) in Terraform?
What most people say
drag me
“I would use Terraform workspaces to switch between environments.”
Workspaces are one option, but they share config and weaken isolation, which is risky for prod (easy to apply to the wrong workspace). A complete answer weighs workspaces vs directory-per-env and isolates prod.
The follow-ups they ask next
What is the risk of using workspaces for prod?
The shared config and backend make it easy to apply to the wrong workspace (you forget you are in prod), and isolation is weaker. Directory/backend-per-env gives prod its own state, credentials, and a clearer blast radius.
How do you avoid duplicating config across environments?
Put the resource definitions in shared modules and have each environment supply only its variables (sizes, counts, names). Environments become the same module with different inputs, not copy-pasted code.
What the interviewer is listening for
- Separate state per environment
- Knows workspaces vs directory-per-env trade-off
- Isolates prod + stays DRY via modules
What sinks the answer
- Workspaces with no caveat
- Shared state across environments
- Copy-pastes config per environment
If you genuinely do not know
Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.
“Each environment needs [its own state so dev can never touch prod]. Options: [workspaces (same config, separate state, convenient but weaker isolation, easy to target the wrong one)] vs [directory/backend per environment (stronger isolation, clearer blast radius, own creds for prod, usually preferred)]. Stay DRY by [sharing modules and varying only per-env inputs].”
Keep going with iac & automation
Foundation
What is Infrastructure as Code, and why use it instead of clicking through the console?
Foundation
What is the difference between declarative and imperative infrastructure as code?
Junior
What is Terraform state, and why does it exist?
Junior
Explain the Terraform workflow: init, plan, and apply.
Mid
Your team provisions infrastructure with code. Why does idempotency matter, and what breaks without it?
Mid
Why do teams use remote state with locking instead of local state?
Knowing the answer is not the same as recalling it under pressure
Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.
Start free