Terraform moved block "managed resource has not been declared" in CI
A moved block records a refactor by mapping an old resource address to a new one. If the "to" address is not actually declared in the config, Terraform cannot complete the move.
What this error means
plan fails saying the resource named in a moved block has not been declared. It happens when the moved-to address was mistyped, or the resource it points at was renamed/removed after the moved block was added.
Error: Moved object still exists
on moved.tf line 1:
1: moved {
2: from = aws_instance.old
3: to = aws_instance.app
A managed resource "aws_instance" "app" has not been declared in the root module.Common causes
moved "to" address not declared
The destination address in the moved block does not correspond to any resource block currently in the configuration.
Target renamed/removed after the move
The resource the moved block points to was later renamed or deleted, leaving the moved block dangling.
How to fix it
Point the moved block at a declared resource
Ensure the "to" address matches an actual resource block, or correct the typo.
resource "aws_instance" "app" {
# ... must exist for the move target
}
moved {
from = aws_instance.old
to = aws_instance.app
}Clean up dangling moves
- Confirm the to-address resource block still exists and is spelled correctly.
- Remove moved blocks whose source no longer appears in any state.
- Run plan to confirm the move resolves cleanly.
How to prevent it
- Keep moved-block targets in sync with declared resources.
- Remove moved blocks only after every state has applied them.
- Run validate/plan after refactors that add moved blocks.