0Pricing
Terraform Infrastructure as Code · Lesson

Refactoring State with moved and removed

Safely rename and restructure resources without destroying infrastructure by using state manipulation commands and the declarative moved and removed blocks.

The Renaming Problem

When you rename a resource in your config, Terraform sees the old address gone and a new one appearing. By default it will destroy and recreate the resource, which can mean downtime or data loss.

State refactoring tools let you tell Terraform that a resource simply moved.

Inspecting State

Start by listing what is tracked in state. The terraform state list command shows every managed resource address.

terraform state list

All lessons in this course

  1. Remote State Backends
  2. State Locking and Consistency
  3. Importing Existing Resources
  4. Refactoring State with moved and removed
← Back to Terraform Infrastructure as Code