Reference to undeclared resource Terraform Origin: Platform & cloud Last updated 14 Oct 2026

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.

Exact message you may see Reference to undeclared resourceReference to undeclared input variableReference to undeclared moduleA managed resource has not been declared in the root 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:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

api_version_invalid — API Error: Invalid or unsupported API version (API)api_version_invalidCS0246 — error CS0246: The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?) (.NET)CS0246feature_not_enabled — API Error: Feature not enabled for this account (feature_not_enabled / not available on your plan) (API)feature_not_enabledInconsistent dependency lock file — Terraform: Error: Inconsistent dependency lock file — provider x: required by this configuration but no version is selected (Terraform)Inconsistent dependen…model_not_found — LLM API: The model `x` does not exist or you do not have access to it (model_not_found / not_found_error) (API)model_not_foundNO_SECRET — NextAuth / Auth.js: [next-auth][error][NO_SECRET] Please define a `secret` in production / MissingSecret (Authentication)NO_SECRETsecretOrPrivateKey must have a value — Error: secretOrPrivateKey must have a value (jsonwebtoken sign) (Authentication)secretOrPrivateKey mu…test/live mismatch — API Error: a similar object exists in test mode, but a live mode key was used (API)test/live mismatchReference…

Explore the map of this error Full error map →

🧠 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.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.