Table of Contents
The Error
Error: Reference to undeclared module / Output not found
What Causes This
You’re referencing a module output that doesn’t exist or the module name is misspelled.
How to Fix It
Solution 1: Declare Output in Module
# modules/vpc/outputs.tf
output "vpc_id" {
value = aws_vpc.main.id
}
Solution 2: Check Module Name
module "networking" { source = "./modules/vpc" }
# Reference: module.networking.vpc_id (NOT module.vpc!)
Solution 3: Debug with Console
terraform console
> module.vpc
Prevention Tips
- Pin provider versions — avoid surprise breaking changes
- Use CI/CD — catch errors before they hit production
- Test with
terraform plan— always review before applying - Keep Terraform updated — newer versions have better error messages
- Use
terraform validate— catches syntax errors early
Hands-On Courses
- Terraform for Beginners on CopyPasteLearn
- Terraform By Example — practical code examples
- Terraform Cheat Sheet — quick reference for all commands
Related Articles
- Terraform Troubleshooting - Common Errors and Solutions
- Terraform Enabling and Using Debugging
- Debugging with TFLint
Conclusion
This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.

