terraform config_error ai_generated true

Error: Output refers to resource that no longer exists

ID: terraform/output-not-found

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

Output block references a resource that was removed from configuration.

generic

Workarounds

  1. 95% success Remove or update the output block to reference existing resources
    # Check what resources exist:
    terraform state list
    
    # Update the output to reference an existing resource:
    output "instance_ip" {
      value = aws_instance.web.public_ip  # must exist in state
    }
    
    # Or remove the output if the resource was deleted:
    # Delete the output block from .tf files

    Sources: https://developer.hashicorp.com/terraform/language/values/outputs

  2. 85% success If the output is consumed by other modules, coordinate the removal
    # Check which modules consume this output:
    grep -r 'module.<module_name>.output_name' *.tf
    
    # Update consumers before removing the output:
    # 1. In the child module: keep the output temporarily
    # 2. In parent modules: update references to new source
    # 3. Run terraform plan to verify no breakage
    # 4. Then safely remove the output

    Sources: https://developer.hashicorp.com/terraform/language/values/outputs

Dead Ends

Common approaches that don't work:

  1. Comment out the output instead of removing 65% fail

    Commented code is dead code — remove it properly

Error Chain

Leads to: