Removing AWS Route Table Routes

Here’s a little oddity with AWS Route Tables within Terraform, if you want to remove all of the routes in a route table, you can’t just delete or comment them out, otherwise it treats them as if nothing has changed.

See the below example, you comment/remove the routes, then in its place add a blank set.

resource "aws_route_table" "inside2_rt" {
  provider = aws.hub
  vpc_id   = aws_vpc.security_vpc.id

  # route {
  #   cidr_block = "10.0.0.0/8"
  #   gateway_id = aws_ec2_transit_gateway.TGW.id
  # }

  # route {
  #   cidr_block = "172.16.0.0/12"
  #   gateway_id = aws_ec2_transit_gateway.TGW.id
  # }

  # route {
  #   cidr_block = "192.168.0.0/16"
  #   gateway_id = aws_ec2_transit_gateway.TGW.id
  # }

  # To Remove the routes, uncomment this; and comment out the routes!
  # route = []

  tags = {
    Name = "inside2_rt"
  }
}

Leave a comment