Reputation: 664
I have two terraform projects. For both projects I am using same credentials and state is stored in S3 bucket. In the first project I create the vpc and the subnets. In the 2nd project I am creating an RDS. I want to put the RDS in the vpc and subnets created in the 1st terraform project. How do I do that?
Thanks!
Upvotes: 0
Views: 469
Reputation: 10117
In the RDS project, pull in the VPC and subnets as data resources. You can pull in the VPC like so:
data "aws_vpc" "my_vpc" {
id = var.vpc_id
}
And you can reference that as data.aws_vpc.my_vpc
.
Depending on your use case, you might want the subnet_ids or subnets data resources to reference subnets as a group.
Data resources are a powerful way to bridge this kind of gap, but if you're not careful with them it can lead to some nasty dependency issues in your build. Keeping networking away from application resources is a sensible division, but consider merging the projects if you expect the networking to change frequently.
Upvotes: 1