terraform refactor_error ai_generated true

Error: Moved object no longer exists or moved block is invalid

ID: terraform/tf-moved-block-error

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

A moved block references a source or destination that does not exist or is invalid.

generic

Workarounds

  1. 88% success Verify both the from and to addresses are valid resource addresses in the current configuration
    moved { from = OLD_ADDRESS; to = NEW_ADDRESS } - OLD_ADDRESS must exist in state, NEW_ADDRESS must exist in config

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

  2. 85% success Use terraform state mv as an alternative for one-time moves
    terraform state mv OLD_ADDRESS NEW_ADDRESS for immediate state change without a moved block

    Sources: https://developer.hashicorp.com/terraform/cli/commands/state/mv

Dead Ends

Common approaches that don't work:

  1. Chain multiple moved blocks to create a move history 80% fail

    Terraform does not support transitive moves; each moved block must reference the current state address directly

  2. Use moved blocks to move resources between different state files 90% fail

    Moved blocks only work within a single state file; cross-state moves require state mv or import

Error Chain

Leads to:
Preceded by: