Terraform: aws_route_table always triggers modify

Created on 7 Aug 2016  ยท  4Comments  ยท  Source: hashicorp/terraform

Hello there!

resource "aws_route_table" "private_1" {
    vpc_id = "${var.vpc_id}"
    route {
        cidr_block = "0.0.0.0/0"
        gateway_id = "${aws_nat_gateway.gw_1.id}"
    }

    tags {
        Name = "uat_platform_private_1"
    }
}

Always triggers terraform to modify a resource:

aws_route_table.private_1: Modifying...
  route.1498634145.cidr_block:                "" => "0.0.0.0/0"
  route.1498634145.gateway_id:                "" => "nat-0509bae43356cedc1"
  route.1498634145.instance_id:               "" => ""
  route.1498634145.nat_gateway_id:            "" => ""
  route.1498634145.network_interface_id:      "" => ""
  route.1498634145.vpc_peering_connection_id: "" => ""
  route.1584724321.cidr_block:                "0.0.0.0/0" => ""
  route.1584724321.gateway_id:                "" => ""
  route.1584724321.instance_id:               "" => ""
  route.1584724321.nat_gateway_id:            "nat-0509bae43356cedc1" => ""
  route.1584724321.network_interface_id:      "" => ""
  route.1584724321.vpc_peering_connection_id: "" => ""

It doesn't happen to public subnet routes, however it has internat gateway attached instead of NAT gateway.

bug provideaws

Most helpful comment

hi @dene14

Thanks for opening the issue here. This is a pretty simple one to solve. You are trying to connect a NAT gateway to the parameter for the Internet Gateway - this is what is causing the continual changes

the code should be:

resource "aws_route_table" "private_1" {
    vpc_id = "${var.vpc_id}"
    route {
        cidr_block = "0.0.0.0/0"
        nat_gateway_id = "${aws_nat_gateway.gw_1.id}"
    }

    tags {
        Name = "uat_platform_private_1"
    }
}

:)

All 4 comments

hi @dene14

Thanks for opening the issue here. This is a pretty simple one to solve. You are trying to connect a NAT gateway to the parameter for the Internet Gateway - this is what is causing the continual changes

the code should be:

resource "aws_route_table" "private_1" {
    vpc_id = "${var.vpc_id}"
    route {
        cidr_block = "0.0.0.0/0"
        nat_gateway_id = "${aws_nat_gateway.gw_1.id}"
    }

    tags {
        Name = "uat_platform_private_1"
    }
}

:)

@stack72 Thanks for blazing fast answer Paul! I wasn't careful enough to check documentation...
However, for my better understanding, has it been done like so on purpose? Isn't route declaration is a simple attachment where router (NAT or IGW) has no any difference?

Hi @dene14

the AWS API actually treats each of these differently:

opts := ec2.CreateRouteInput{
                RouteTableId:           aws.String(d.Id()),
                DestinationCidrBlock:   aws.String(m["cidr_block"].(string)),
                GatewayId:              aws.String(m["gateway_id"].(string)),
                InstanceId:             aws.String(m["instance_id"].(string)),
                VpcPeeringConnectionId: aws.String(m["vpc_peering_connection_id"].(string)),
                NetworkInterfaceId:     aws.String(m["network_interface_id"].(string)),
            }

            if m["nat_gateway_id"].(string) != "" {
                opts.NatGatewayId = aws.String(m["nat_gateway_id"].(string))
            }

So we need to be clear that when some means a nat_gateway, that is what we pass to the API. We thought about trying something like checking for string prefixes but that would have broken potential naming changes from AWS

P.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings