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:
terraform apply
terraform output vpc_idIf the value is inside a module (e.g., a networking module), expose it at root level:
# 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:
terraform apply
terraform output vpc_id
# "vpc-0abc123def456"To list all available outputs in the current state:
terraform outputLesson: terraform output only works after terraform apply, and module outputs must be explicitly re-exported at root level to be visible.