Skip to content
Latchkey

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.

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

main.tf
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

  1. Ensure each to address is declared exactly once.
  2. Do not have two moved blocks target the same address.
  3. 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 moved from old → new.
  • Keep moved blocks until every environment has applied the rename.
  • Run terraform validate/plan to confirm the move is clean before merge.

Related guides

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