Hello everyone. I am relatively new to Terraform. I have recently begun to work with modules. I suspect my issue lays with my lack of fully understanding modules, however, I am eager to learn.
I am encountering an issue (probably of my own fault) where Terraform is creating duplicate VPC resources. Namely, 3 duplicate VPC’s, 3 duplicate subnets, 3 duplicate route tables, etc.
I have my root main.tf that calls three modules that I have created. Those modules are ‘vpc’, ‘routes’, and ‘watchguard.’ The ‘watchguard’ module is for a layer 7 cloud firewall.
In my Watchguard output.tf I am outputting the ID of the ENI on the private subnet.
#Outputs Watchguard private ENI id of the Firebox
output "wg_private" {
value = aws_network_interface.Watchguard_Private.id
}
The ‘routes’ module is calling the ‘watchguard’ module.
module "watchguard" {
source = "../watchguard"
}
Inside of the ‘routes’ module i have several route tables that use the ENI of Watchguard for their 0 route. This same ‘route’ module also calls on the ‘vpc’ module for the VPC id output.
resource "aws_route_table" "primary_private_route_table" {
vpc_id = module.vpc.prod_vpc_id
route {
cidr_block = "0.0.0.0/0"
network_interface_id = module.watchguard.wg_private
}
tags = {
Name = "Primary Private"
}
} # end resource
As I mentioned at the beginning of my post, when i execute a terraform plan, it shows that Terraform will create (and it does) 3 duplicates of each VPC resource. I am assuming that this is because both the ‘routes’ and ‘watchguard’ module both call the ‘vpc’ module. Is this behavior expected? How do I go about just pulling in the outputs that i need and not the entire module again?
Thank you so much for your help!