Interview Prep/Terraform/Refactoring, Migration and Drift

How do you merge two states?

IntermediateProductionRefactoring, Migration and Drift
Answer

Move resources from stack B into A with terraform state mv -state=b.tfstate -state-out=a.tfstate ADDR ADDR (after pulling both and with backups), copy the matching config blocks into A and plan for zero diff before pushing. For many resources, using import blocks in A and removed in B is easier to review and safer.

All Terraform questions Roadmap: Terraform in production

More on Refactoring, Migration and Drift