terraform state_error ai_generated partial

Error: Module output depends on resource that no longer exists

ID: terraform/depends-on-module

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

Module references a resource that was removed from config but exists in state.

generic

Workarounds

  1. 92% success Use terraform state rm to remove the orphaned resource from state
    terraform state rm module.name.resource_type.name

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

  2. 85% success Run terraform plan to see what will change, then targeted apply if needed
    terraform plan -target=module.name

    Sources: https://developer.hashicorp.com/terraform/cli/commands/plan

  3. 82% success Use terraform state list to inventory what's tracked vs what's in config
    Use terraform state list to inventory what's tracked vs what's in config

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

Dead Ends

Common approaches that don't work:

  1. Delete the entire module and recreate 75% fail

    Destroys all resources in the module — may cause outage

  2. Manually edit the state JSON 80% fail

    Error-prone — one mistake can corrupt the entire state

Error Chain

Frequently confused with: