Reference to undeclared resource 🟪 Terraform

Terraform: Error: Reference to undeclared resource / Reference to undeclared input variable

The configuration refers to a resource, data source, variable or module output that isn’t declared in this module.

Seen on: Terraform

Meaning

Typos in resource names, referencing resources from another module directly (instead of outputs), missing variable blocks, or a file not in the working directory cause it.

Common causes

  • Typo in type or name (aws_s3_bucket.logs vs .log)
  • Referencing another module’s resource instead of its output
  • Variable used but no variable block
  • Running from the wrong directory

⚡ Quick fix

  1. Fix the reference name/type
  2. Expose values with outputs and use module.x.output
  3. Declare the variable block

Detailed fix by platform

HCL

  1. hcl
    variable "env" { type = string }
    output "bucket_arn" { value = aws_s3_bucket.logs.arn }
    # elsewhere: module.storage.bucket_arn

How to diagnose

  1. Name — Exact reference
  2. Scope — Same module?
  3. Dir — terraform executed where?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.