Moved and Removed Blocks

Scenario: A team splits a monolithic root into modules and Terraform interprets every new address as a new object.

moved blocks declare address migrations so Terraform preserves identity across renames, module extraction, and repetition changes. removed blocks can declare that Terraform should stop managing an object, optionally destroying or retaining it depending on lifecycle settings and version capabilities. Keep migration blocks long enough for all relevant states to pass through the release.

Analogy: A forwarding address must remain until every correspondent has learned the new location. Removing it too early strands states on old versions.

A worked configuration

moved {
  from = fakecloud_server.api
  to   = module.service.fakecloud_server.api
}
removed {
  from = fakecloud_server.retired
  lifecycle { destroy = false }
}

Plan migrations against representative state snapshots, roll forward in controlled stages, and prevent older code from applying after migration. State schema changes are deployments in their own right.

Note: Treat the plan as a change contract: understand every create, update, replacement, and destroy before approving it.
Goal: Reinforce this lesson in the tf-moved-refactor Terraform lab. Open /labs/terraform and choose slug tf-moved-refactor; the lab runs real Terraform against the offline FakeCloud provider.