Referencing output of resource outside the module

So I’ve spent the last couple of days banging my head against this, and I’m hoping that someone can point me in the right direction. I’ve got an AWS VPC terraform module that works totally fine and I can use a parent module to call it and input the variables and all that jazz.

What I’m trying to do is take the output of specific modules (ex. aws_vpc.*.id amongst others) and reference/call them from another child module in the same directory.

Folder Structure:
-dev
|-- main.tf <- this works great with the VPC module
-modules
|–VPC
|— stuff-with-outputs.tf <- want to reference resource ID’s from this module
|–EC2
|—stuff-that-I-am-calling-from.tf <- wanting to reuse said resources so I keep my code dry.

Any assistance would be greatly appreciated!

1 Like

Without seeing your code I’m only guessing, but if in ‘main.tf’ you are creating a module called ‘foo’ with source being ‘modules/VPC’, then in EC2’s Terraform file you’ll need to refer to outputs from the VPC module as module.foo.<output name>.

Yep! I should’ve closed this, as I got it figured out. Thanks for responding!

1 Like