From c42113494a06f8a44e7950ae67b0f95531a76e77 Mon Sep 17 00:00:00 2001 From: Calvin French-Owen Date: Wed, 14 Sep 2016 16:45:50 -0700 Subject: [PATCH] vpc: split routes This commit preserves the same behavior around stack, but instead allows us to define route associations outside of the stack itself and still use the VPC module. It's due to a known ordering issue in Terraform https://www.terraform.io/docs/providers/aws/r/route.html --- vpc/main.tf | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/vpc/main.tf b/vpc/main.tf index 9bb5bce3..683614c8 100644 --- a/vpc/main.tf +++ b/vpc/main.tf @@ -97,30 +97,33 @@ resource "aws_subnet" "external" { resource "aws_route_table" "external" { vpc_id = "${aws_vpc.main.id}" - route { - cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.main.id}" - } - tags { Name = "${var.name}-external-001" } } +resource "aws_route" "external" { + route_table_id = "${aws_route_table.external.id}" + destination_cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.main.id}" +} + resource "aws_route_table" "internal" { count = "${length(compact(split(",", var.internal_subnets)))}" vpc_id = "${aws_vpc.main.id}" - route { - cidr_block = "0.0.0.0/0" - nat_gateway_id = "${element(aws_nat_gateway.main.*.id, count.index)}" - } - tags { Name = "${var.name}-${format("internal-%03d", count.index+1)}" } } +resource "aws_route" "internal" { + count = "${length(compact(split(",", var.internal_subnets)))}" + route_table_id = "${element(aws_route_table.internal.*.id, count.index)}" + destination_cidr_block = "0.0.0.0/0" + nat_gateway_id = "${element(aws_nat_gateway.main.*.id, count.index)}" +} + /** * Route associations */