🎉 DevOps Interview Prep Bundle is live — 1000+ Q&A across 20 topicsGet it →
All Fixes
Today I Fixed

terraform output showing null or 'output variable could not be found'

terraformJun 30, 202610 minutes to fixterraformtroubleshooting

Ran terraform output vpc_id and got either null or The output variable requested could not be found. The resource existed in the state file — I could see it with terraform show.

Root cause: Two separate issues cause this. First, terraform output reads from the last applied state — if you haven't run terraform apply yet (or only ran terraform plan), outputs are empty. Second, if the output is declared inside a module, it won't be visible at root level unless you re-expose it with an explicit output block in the root module.

Fix:

First, make sure you've actually applied:

bash
terraform apply
terraform output vpc_id

If the value is inside a module (e.g., a networking module), expose it at root level:

hcl
# modules/networking/outputs.tf
output "vpc_id" {
  value = aws_vpc.main.id
}
 
# root outputs.tf  <-- this was missing
output "vpc_id" {
  value = module.networking.vpc_id
}

Then re-apply and query:

bash
terraform apply
terraform output vpc_id
# "vpc-0abc123def456"

To list all available outputs in the current state:

bash
terraform output

Lesson: terraform output only works after terraform apply, and module outputs must be explicitly re-exported at root level to be visible.