How to fix Error: Moved block with ambiguous destination in Terraform

TerraformINTERMEDIATEMEDIUMUpdated Dec 30, 2025· 155 views

The "Moved block with ambiguous destination" error occurs when multiple moved blocks in your Terraform configuration target the same destination resource. Terraform cannot determine which source should be moved to that destination, creating ambiguity that prevents the refactoring from proceeding.

Quick fix

Fixes Error: Moved block with ambiguous destination

grep -r "to.*=" . --include="*.tf" | grep moved -A 2
  1. Identify all moved blocks targeting the same destination
  2. Determine which source is correct
  3. Remove redundant or incorrect moved blocks
  4. Handle multiple sources that both exist
terraform — error
grep -r "to.*=" . --include="*.tf" | grep moved -A 2
Error: Moved block with ambiguous destination

What this error means

Terraform's moved block is used to refactor infrastructure code by telling Terraform that a resource has been renamed or relocated without destroying and recreating it. However, each resource can only have one source—it can only be moved from one previous location. When you have multiple moved blocks that conflict by pointing to the same destination, Terraform cannot determine which source is the correct origin. This creates an ambiguous situation where the refactoring cannot be safely applied. The error prevents the configuration from being evaluated because Terraform needs absolute clarity about which resource in your state file maps to which resource in your code.

Typical symptoms

  • Terraform plan or apply fails with 'Error: Moved block with ambiguous destination'
  • Error message shows a resource address that is targeted by multiple moved blocks
  • Error indicates 'Each resource can have moved from only one source resource'
  • Terraform cannot proceed when you have conflicting moved blocks in the same configuration
  • The error occurs after refactoring resource names or module structure

Common causes

  1. Multiple moved blocks with different from addresses but the same to (destination) address
  2. Two or more moved blocks trying to move different resources into the same destination
  3. Conflicting refactoring changes that both target the same resource location
  4. Module interactions where both a parent and child module declare moves to the same resource
  5. Accidental duplication of moved blocks during configuration edits

How to fix "Error: Moved block with ambiguous destination"

1Identify all moved blocks targeting the same destination

First, find which moved blocks are conflicting. Search your configuration files for all moved blocks that have the same to address:

bash
grep -r "to.*=" . --include="*.tf" | grep moved -A 2

Or manually review your moved blocks. The error message should tell you which destination is ambiguous. For example:

hcl
# These two blocks conflict
moved {
  from = aws_instance.old_name_1
  to   = aws_instance.new_name  # First source
}

moved {
  from = aws_instance.old_name_2
  to   = aws_instance.new_name  # Second source - CONFLICT!
}

List all moved blocks that point to the same destination.

2Determine which source is correct

Examine your Terraform state file to see which resource actually exists:

bash
terraform state list | grep -E "old_name|new_name"

Or view more detail with:

bash
terraform state show aws_instance.old_name_1
terraform state show aws_instance.old_name_2

This will show you which resource currently exists in your state. You need to identify:
- Which from address corresponds to an actual resource in your state
- Whether both exist (in which case you need to consolidate them first)
- Which refactoring move is the correct one

Only one of the conflicting moved blocks should be valid.

3Remove redundant or incorrect moved blocks

Delete the moved blocks that are not correct. Keep only the moved block that accurately reflects how your state needs to be remapped:

hcl
# KEEP THIS - if old_name_1 is the actual resource
moved {
  from = aws_instance.old_name_1
  to   = aws_instance.new_name
}

# DELETE THIS - remove the conflicting block
# moved {
#   from = aws_instance.old_name_2
#   to   = aws_instance.new_name
# }

After removing the conflicting moved block, run:

bash
terraform plan

The error should resolve.

4Handle multiple sources that both exist

If both source resources actually exist in your state file and you genuinely need to consolidate them, you cannot use a single moved block. Instead:

1. Manually consolidate in state first:

bash
# Remove the state of one resource (keeping the other)
terraform state rm aws_instance.old_name_2

2. Then apply your moved block:

hcl
moved {
  from = aws_instance.old_name_1
  to   = aws_instance.new_name
}

3. Plan and apply:

bash
terraform plan
terraform apply

Be careful with this approach—removing state should only be done when you're certain that resource instance is no longer needed.

5Review moved blocks for module interactions

If you're using modules, check for conflicts across module boundaries:

hcl
# Parent module
moved {
  from = module.networking.aws_vpc.main
  to   = aws_vpc.shared
}

# Child module (networking/main.tf)
moved {
  from = aws_vpc.main
  to   = aws_vpc.consolidated  # Different destination
}

If you have moved blocks in both parent and child modules targeting overlapping resources, you need to:
- Keep moved blocks only at the appropriate scope
- Remove duplication across module boundaries
- Ensure only one moved block per resource address

Simplify to have moved blocks at just one level (either parent or child, not both).

Advanced notes

Why does this restriction exist?

Terraform's state file is the source of truth for your infrastructure. When you apply a moved block, Terraform remaps the state so the same physical resource (identified by its unique ID in the cloud) gets a new logical address in your code.

The ambiguity rule prevents data loss: if multiple moved blocks targeted the same destination, Terraform would not know which source's state data to move there, risking overwriting one resource's state with another's.

Implicit moved blocks

In some cases, Terraform may automatically detect renames and generate implicit moved blocks. These can sometimes cause ambiguity if the detection is unclear. To debug:

bash
terraform plan -json | jq '.diagnostic_events | select(.summary == "Moved'

Preventing this error:

- Plan your refactoring carefully before writing moved blocks
- Use a naming convention that makes the before/after clear
- Apply moved blocks incrementally: refactor one module at a time
- Test in a non-production environment first
- Keep moved blocks close to the resources they affect (avoid cross-module moves unless necessary)
- Document why each moved block exists with comments

Related limitation: Terraform does not support dynamic moved blocks (e.g., using for_each or count to generate moved blocks). Each move must be explicitly declared.

Frequently asked questions

What does "Error: Moved block with ambiguous destination" mean?
Terraform's moved block is used to refactor infrastructure code by telling Terraform that a resource has been renamed or relocated without destroying and recreating it. However, each resource can only have one source—it can only be moved from one previous location. When you have multiple moved blocks that conflict by pointing to the same destination, Terraform cannot determine which source is the correct origin.
How do I fix "Error: Moved block with ambiguous destination"?
The "Moved block with ambiguous destination" error occurs when multiple moved blocks in your Terraform configuration target the same destination resource. Terraform cannot determine which source should be moved to that destination, creating ambiguity that prevents the refactoring from proceeding.
What causes "Error: Moved block with ambiguous destination"?
Multiple moved blocks with different from addresses but the same to (destination) address Two or more moved blocks trying to move different resources into the same destination Conflicting refactoring changes that both target the same resource location
Is the "Error: Moved block with ambiguous destination" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading