What is your workflow for refactoring Terraform safely?
IntermediateProductionRefactoring, Migration and Drift
Answer
Make the change in a branch, add moved blocks for renamed or relocated addresses and run terraform plan: the goal is "no changes" (plus move notes). Apply in dev first. If the plan shows destroy and create where you expected a move, stop and fix the addresses. Never combine a refactor with a functional change in one PR.
More on Refactoring, Migration and Drift
How 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 merge two states?IntermediateHow 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