Interview Prep/Terraform/State Backends and Workspaces

Move from local state to S3 for an existing project without losing anything.

IntermediateScenarioState Backends and Workspaces
Answer

Situation read → Existing resources, existing local state.

What I'd do →

  1. Back up terraform.tfstate.
  2. Add the backend "s3" block.
  3. Run terraform init -migrate-state and answer yes to copy.
  4. Run terraform plan; it should be clean.
  5. Delete the local state file after verifying the remote object.

Why → -migrate-state copies state with its lineage and serial, so nothing is re-imported.

Interview tip → Check the plan is empty before telling anyone it worked.

All Terraform questions Roadmap: Terraform in production

More on State Backends and Workspaces