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.
Reference to undeclared resourceReference to undeclared input variableReference to undeclared moduleA managed resource has not been declared in the root module 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
- Fix the reference name/type
- Expose values with outputs and use module.x.output
- Declare the variable block
Detailed fix by platform
HCL
- hcl
variable "env" { type = string } output "bucket_arn" { value = aws_s3_bucket.logs.arn } # elsewhere: module.storage.bucket_arn
How to diagnose
- Name — Exact reference
- Scope — Same module?
- 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:
Similar errors
- api_version_invalid API Error: Invalid or unsupported API version
- CS0246 error CS0246: The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?)
- feature_not_enabled API Error: Feature not enabled for this account (feature_not_enabled / not available on your plan)
Most viewed in Terraform
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 14 Oct 2026