Terraform "moved" Block Errors - Invalid or Conflicting Address in CI
A moved {} block tells Terraform a resource was renamed so state follows without destroy/recreate. It errors when the from/to addresses are malformed, the old address is still declared, or two moves collide.
What this error means
plan fails on a moved block - the to address does not exist as a resource, the from resource is still declared, or two moved blocks target the same address. The rename does not take effect.
Error: Moved object still exists
on moved.tf line 1:
1: moved {
This statement declares a move from aws_instance.web to aws_instance.app, but
aws_instance.web is still declared in the configuration.
Each moved block must specify a move from an object that no longer exists.Common causes
Old address still declared
The from resource must no longer exist in config. If you kept the old resource block while adding a moved to a new name, Terraform rejects the move.
Target address missing or duplicated
The to address must name a resource that exists in the config. Two moved blocks pointing at the same to, or a to that does not exist, collide.
How to fix it
Rename the resource and move state, removing the old block
Delete the old resource block, add the renamed one, and add a single moved from old to new.
resource "aws_instance" "app" { # renamed from "web"
ami = var.ami
instance_type = "t3.micro"
}
moved {
from = aws_instance.web
to = aws_instance.app
}Resolve colliding or chained moves
- Ensure each
toaddress is declared exactly once. - Do not have two
movedblocks target the same address. - For a chain (A→B→C), keep both links until all states have caught up.
How to prevent it
- When renaming, remove the old block and add one
movedfrom old → new. - Keep
movedblocks until every environment has applied the rename. - Run
terraform validate/planto confirm the move is clean before merge.