I am using terraform and terragrunt for my companies aws infrastructure, general structure is like this, i have two main folder, one for modules, other one for environments and sourcing modules to environment folder using terragrunt, one module is for general vpc infrastructure, i have separate module for vpc-peering, i created separated folders for vpc and vpc-peering in environment folder, so both of them has different terraform state on s3, the problem is that vpc-peering is creating route-tables also and when i want to apply some changes on vpc module it deletes records created from vpc-peering module, is there any way to inject route tables into vpc module? I know that i can move vpc-peering module into vpc and have one both module but it takes quite some time to rewrite all the stuff and i would love to know any other way.
Terraform state conflict between vpc and vpc-peering modules
420 views Asked by Lado Golijashvili At
2
There are 2 answers
0
On
I am not sure if you are using git as source code for the terraform, if yes then you can keep the modules in the separate git repository and call the module for route table as you want.
eg. :
resouces "aws_route" "public_igw_route" {
source = "[email protected]:user/infra-modules.git//aws-route"
}
They shouldn't both be creating route tables. The VPC module should be creating route tables, and the VPC Peering module should be adding routes to those route tables. The trick here is to not create any routes in the
aws_route_table
resources, but create them all as separateaws_route
resources. Per the note in theaws_route
documentation:So in order to define routes in multiple modules you will need to use the
aws_route
resource for all route definitions.