moved block — a safe, declarative way to refactor resource addresses in your configuration without modifying the underlying infrastructure or manually editing the state file. Use this when you want to rename resources or move them into modules while keeping the existing cloud objects intact.
Why you need it
- During early development you might give resources short or ambiguous names (for example
vpcandvpc1). As the project grows you’ll want clearer names (for examplesbx_vpcandtest_vpc). - Simply renaming a resource in HCL makes Terraform think the old address was removed and a new one created. The result: Terraform plans to destroy the existing resource and create a new one — potentially causing downtime or data loss.
aws_vpc.vpc to aws_vpc.sbx_vpc directly in your HCL, Terraform will show a plan that destroys the old address and creates a new one:

main.tf into logical child modules (for example network, security, compute, database). From Terraform’s perspective the addresses differ: aws_instance.web_server is not the same as module.compute.aws_instance.web_server. Without telling Terraform about the move, it will attempt to recreate the resources under the new module addresses.

- The
movedblock maps an old resource address to a new one so Terraform updates its state without performing provider API calls. - Terraform updates only its internal state file; no infrastructure is destroyed or recreated.
- Use it to rename resources or to move resources into/out of modules safely.

moved
| Use case | Description |
|---|---|
| Rename a resource | Change aws_vpc.vpc → aws_vpc.sbx_vpc without recreating the VPC. |
| Move into a module | Change aws_s3_bucket.data → module.storage.aws_s3_bucket.data. |
| Move between modules / rename modules | Change module.old_app.aws_instance.app → module.new_app.aws_instance.app. |
- The block is declarative and simple: provide
fromandto, both as string resource addresses.
moved blocks
- Add the destination resources to your configuration first.
- If moving into a module, create the module definition and include the resource blocks.
- Add one or more
movedblocks mapping old addresses to new addresses.- You can put these mappings in a dedicated file such as
moved.tffor clarity.
- You can put these mappings in a dedicated file such as
- Run
terraform planto validate. Expect state move operations — not create/destroy of cloud resources. - Run
terraform applyto update the state file. This is fast because it updates only Terraform’s state. - After successful apply you can remove the
movedblocks (or keep them as documentation).
The
moved blocks are temporary state-migration scaffolding. Once applied they are no longer required for Terraform to track the resources at their new addresses, though many teams keep them in moved.tf for auditability.- Terraform docs — State: Move resources: https://www.terraform.io/docs/cli/commands/state/move.html
- Terraform docs — Configuration language: resource addresses: https://www.terraform.io/docs/language/state/resource-addressing.html
- Use the
movedblock to refactor resource addresses without changing infrastructure. - Always add destination resources first, then declare
movedmappings, thenplanandapply. - This approach keeps your refactor safe, auditable, and fast — no downtime and no manual state edits.
