terraform refactoring ai_generated true

Error: Moved object still exists

ID: terraform/moved-block-error

Also available as: JSON · Markdown
92%Fix Rate
94%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
115 active
1 active

Root Cause

A moved block references a resource that still exists in the configuration.

generic

Workarounds

  1. 94% success Remove the old resource block after adding the moved block
    moved { from = old_address; to = new_address } — then delete the old resource block

    Sources: https://developer.hashicorp.com/terraform/language/modules/develop/refactoring

  2. 90% success Run terraform plan to verify the move before applying
    Plan should show 'moved' not 'destroy/create'

Dead Ends

Common approaches that don't work:

  1. Removing the moved block and running apply 80% fail

    Terraform will try to destroy the old resource and create a new one

  2. Using terraform state rm to remove the old address 65% fail

    May lose track of the resource; potential orphaned infrastructure

Error Chain

Frequently confused with: