2

Thanks in advance if you know the answer!

When I add the routing for multiple subnets like this for cross account vpc peering it forces a new resource every apply

resource "aws_route" "route" {
  count                     = "${var.first_route_table_count}"
  route_table_id            = "${element(var.first_route_table_ids, count.index)}"
  destination_cidr_block    = "${data.aws_vpc.second_vpc.cidr_block}"
  vpc_peering_connection_id = "${aws_vpc_peering_connection.peer.id}"
}

resource "aws_route" "second_account_route" {
  provider                  = "aws.second_account"
  count                     = "${var.second_route_table_count}"
  route_table_id            = "${element(var.second_route_table_ids, count.index)}"
  destination_cidr_block    = "${data.aws_vpc.first_vpc.cidr_block}"
  vpc_peering_connection_id = "${aws_vpc_peering_connection.peer.id}"
}

1 Answers1

2

Here is the solution if anyone comes across this Terraform quirk in the future..

Ive come to realise that because I am defining a route table and a route together that you cannot add another route later.

The solution to this is to create a route table with no routes, then add all other routes separately.

  • 1
    They _sort_ of tell you this in their docs, by not very clearly. I just ran into this. You need to create a `aws_route_table` resource with no "inline" `route{}` then multiple `aws_route`s to update it – red888 Aug 07 '18 at 01:12