Terraform - how to to Reference Output Variable from Nested Module in Root Module
I'm writing unit tests and I'm performance testing and I recently switched to After trying multiple solutions online, I still can't figure this out... I'm trying to reference an output variable from a nested module in my root module, but I'm running into issues where Terraform seems to not recognize the output. I have a structure where I have a main module that calls a nested module for creating an EC2 instance. In my nested module, I define an output variable for the instance ID, but when I try to access this output in the root module, I get the behavior: `behavior: Missing resource instance`. Here's how my directory structure looks: ``` âââ main.tf âââ variables.tf âââ modules/ âââ ec2_instance/ âââ main.tf âââ outputs.tf ``` In `modules/ec2_instance/main.tf`, I create the EC2 instance like this: ```hcl resource "aws_instance" "my_instance" { ami = var.ami_id instance_type = var.instance_type } ``` And then, in `modules/ec2_instance/outputs.tf`, I have the output defined: ```hcl output "instance_id" { value = aws_instance.my_instance.id } ``` In my root `main.tf`, I'm trying to call it like this: ```hcl module "ec2_instance" { source = "./modules/ec2_instance" ami_id = var.ami_id instance_type = var.instance_type } output "instance_id" { value = module.ec2_instance.instance_id } ``` When I run `terraform apply`, I get the behavior about the missing resource instance. I've already confirmed that the module path is correct and that the nested module is being called properly. I've also made sure that I have the right variable types in `variables.tf`. Any suggestions on what could be going wrong or any best practices for referencing outputs in nested modules? I'm working on a CLI tool that needs to handle this. Am I missing something obvious? This is happening in both development and production on macOS. Could this be a known issue? This is part of a larger application I'm building. I'd love to hear your thoughts on this. The project is a REST API built with Hcl. I'd really appreciate any guidance on this.