CodexBloom - Programming Q&A Platform

Terraform Module Outputs Not Accessible in Root Module with Multiple Workspaces

👀 Views: 86 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-18
terraform aws modules HCL

I'm trying to debug I'm stuck on something that should probably be simple. I'm experiencing an issue where outputs from a child module are not accessible in the root module when using multiple Terraform workspaces. My setup consists of a `vpc` module that creates a VPC and its associated resources, and I expect to access outputs like `vpc_id` and `subnet_ids` in the root module. However, when I run `terraform output` from my root module, I receive an empty output for those values. I've confirmed that the VPC module is working fine in a single workspace setup, as I can see the expected outputs when I run `terraform output` without workspaces. Here's a simplified version of my code: In the `vpc` module (`modules/vpc/main.tf`): ```hcl resource "aws_vpc" "main" { cidr_block = "10.0.0.0/16" } output "vpc_id" { value = aws_vpc.main.id } output "subnet_ids" { value = aws_subnet.main[*].id } ``` In the root module (`main.tf`): ```hcl module "vpc" { source = "./modules/vpc" } output "vpc_id" { value = module.vpc.vpc_id } output "subnet_ids" { value = module.vpc.subnet_ids } } ``` When I switch to different workspaces, the outputs seem to be missing. I've tried running `terraform apply` in each workspace to ensure that resources are created afresh, but still, the outputs do not show up. I'm using Terraform version 1.3.5 and the AWS provider version 4.0.0. Is there something I'm overlooking regarding state management with multiple workspaces, or is there a specific way I need to handle outputs in this context? Any insights would be appreciated! This is my first time working with Hcl 3.10. Could this be a known issue?