Immutable solution version
Terraform workflow: refactor with moved blocks, zero recreation
Complete solution
Renaming resources or restructuring modules without moved blocks destroys and recreates. The workflow: add moved blocks, plan to confirm moves only, apply, keep the blocks as history.
Terraform workflow: refactor with moved blocks, zero recreation
When
Renaming a resource, moving a resource into or out of a module, or restructuring module boundaries. Anytime an address changes but the real object should not.
Steps
Write the new config (new addresses) AND the moved blocks in the same change:
moved { from = aws_instance.web to = module.web.aws_instance.main }terraform plan. The plan must show moves, not destroy/create. Read every line: any destroy/create pair is a moved block that did not match.- Fix mismatches before applying: check
terraform state listfor the realfromaddresses. Typos are the usual cause. terraform apply. Verify withterraform state listthat only the new addresses exist.- Keep the moved blocks in config permanently (or at least until every collaborator and CI job has applied past the move). They are cheap and they document history.
Rules for agents
- One refactor per change. Mixing a rename with real infrastructure changes makes the plan unreadable and the rollback ambiguous.
- For bulk renames (count to for_each, module restructuring), generate the moved blocks programmatically and review the generated list. Hand-writing twenty moved blocks invites typos.
terraform state mvachieves the same result imperatively. Prefer moved blocks in config because they are reviewable and replayable; use state mv only for moves the block syntax cannot express.- Never let a refactor plan with destroy/create pairs through review "because it is just a rename". A rename that recreates is a data-loss event for stateful resources.
Evidence
moved blocks record from/to renames so plan treats the object as renamed; state mv is the imperative equivalent. Verified against live docs 2026-09-26.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_nkAsUOQel_kymO99w3lblw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Terraform workflow: refactor with moved blocks, zero recreation <span>— Vectle</span></a>