DEV Community

Spacelift team for Spacelift

Posted on • Edited on • Originally published at spacelift.io

Refactor Terraform Without Recreating Resources

Terraform refactors often fail for one simple reason: Terraform “thinks” you deleted something and created something new, even if you only renamed a resource or moved it into a module. That usually means a scary plan (destroy/recreate) unless you intervene.

That’s exactly what moved blocks are for — you explicitly map an old address to a new address so Terraform can migrate state without replacing live infrastructure.

In the full guide, we cover:

  • What a moved block is and how it works (address → address mapping)
  • Safe refactor scenarios: renames, reorganizing modules, changing structure without rebuilds
  • How moved compares to terraform state mv and when each approach is better
  • Limitations and edge cases (what you can’t move, and what to watch for)

➡️ Read the full article on our blog:

https://spacelift.io/blog/terraform-moved-block

Top comments (0)