Skip to content
Latchkey

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.

terraform
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.

main.tf
resource "aws_instance" "app" {
  # ... must exist for the move target
}

moved {
  from = aws_instance.old
  to   = aws_instance.app
}

Clean up dangling moves

  1. Confirm the to-address resource block still exists and is spelled correctly.
  2. Remove moved blocks whose source no longer appears in any state.
  3. 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →