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

  1. Pin provider versions — avoid surprise breaking changes
  2. Use CI/CD — catch errors before they hit production
  3. Test with terraform plan — always review before applying
  4. Keep Terraform updated — newer versions have better error messages
  5. Use terraform validate — catches syntax errors early

Hands-On Courses

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.