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.
More on Refactoring, Migration and Drift
What is your workflow for refactoring Terraform safely?IntermediateHow do you rename a resource inside a shared module without breaking consumers?AdvancedHow do you split one state into two without downtime?AdvancedHow do you import a large existing environment efficiently?IntermediateHow do you upgrade a major version of the AWS provider?AdvancedHow do you upgrade the Terraform CLI across many stacks?Intermediate