Search code examples
amazon-web-servicesterraformaws-vpcterraform-provider-aws

Terraform Route Table forcing new resource every apply


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}"
}

Solution

  • 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.