Interview Prep/Terraform/State Backends and Workspaces

A giant state with 1,500 resources must be split into network and app states. How do you do it safely?

AdvancedScenarioState Backends and Workspaces
Answer

Situation read → You must move resources between states without destroying anything.

What I'd do →

  1. Back up the state (terraform state pull > backup.tfstate).
  2. Write the new root module, with the same resource code.
  3. Use terraform state mv -state-out=new.tfstate ... for each resource, or import blocks in the new stack and removed blocks in the old one.
  4. Push the new state to the new backend and run terraform plan in both: both must be clean.
  5. Do it in a maintenance window with locks held.

Why → Each step is reversible via the backup, and clean plans prove the split is correct.

Interview tip → Prefer import and removed blocks for reviewability; state mv is imperative.

All Terraform questions Roadmap: Terraform in production

More on State Backends and Workspaces