Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use network_interface_id within aws_route_table without incurring a diff everytime #1426

Closed
rene00 opened this issue Aug 16, 2017 · 20 comments
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@rene00
Copy link

rene00 commented Aug 16, 2017

Terraform Version

$ terraform -v
Terraform v0.10.1

Affected Resource(s)

  • aws_route_table

Terraform Configuration Files

provider "aws" {
  region = "ap-southeast-2"
  alias  = "local"
}

resource "aws_vpc" "default" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "subnet1" {
  vpc_id            = "${aws_vpc.default.id}"
  availability_zone = "ap-southeast-2a"
  cidr_block        = "10.0.1.0/24"
}

resource "aws_subnet" "subnet2" {
  vpc_id            = "${aws_vpc.default.id}"
  availability_zone = "ap-southeast-2a"
  cidr_block        = "10.0.2.0/24"
}

resource "aws_instance" "server" {
  instance_type = "t2.nano"
  ami           = "ami-ae6259cd"
  subnet_id     = "${aws_subnet.subnet1.id}"
}

resource "aws_network_interface" "test" {
  subnet_id   = "${aws_subnet.subnet2.id}"
  private_ips = ["10.0.2.100"]

  attachment {
    instance     = "${aws_instance.server.id}"
    device_index = 1
  }
}

resource "aws_route_table" "rt" {
  vpc_id = "${aws_vpc.default.id}"

  route {
    cidr_block           = "10.1.1.1/32"
    network_interface_id = "${aws_network_interface.test.id}"
  }
}

Expected Behavior

Running terraform apply for the second time there should be no modifications.

Actual Behavior

Running terraform apply for the second time there are modifications.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply
  2. terraform apply again.

Important Factoids

network_interface_id or instance_id can be set for routes within aws_route_table though when setting network_interface_id it appears AWS sends back instance_id AND network_interface_id which triggers a diff.

$ terraform apply
...
Apply complete! Resources: 6 added, 0 changed, 0 destroyed.
$ terraform apply
...
aws_route_table.rt: Modifying... (ID: rtb-4b30d52c)
  route.1660468403.cidr_block:                "" => "10.1.1.1/32"
  route.1660468403.egress_only_gateway_id:    "" => ""
  route.1660468403.gateway_id:                "" => ""
  route.1660468403.instance_id:               "" => ""
  route.1660468403.ipv6_cidr_block:           "" => ""
  route.1660468403.nat_gateway_id:            "" => ""
  route.1660468403.network_interface_id:      "" => "eni-38498645"
  route.1660468403.vpc_peering_connection_id: "" => ""
  route.2141106289.cidr_block:                "10.1.1.1/32" => ""
  route.2141106289.egress_only_gateway_id:    "" => ""
  route.2141106289.gateway_id:                "" => ""
  route.2141106289.instance_id:               "i-06fbffdd7ceb7026f" => ""
  route.2141106289.ipv6_cidr_block:           "" => ""
  route.2141106289.nat_gateway_id:            "" => ""
  route.2141106289.network_interface_id:      "eni-38498645" => ""
  route.2141106289.vpc_peering_connection_id: "" => ""
aws_route_table.rt: Modifications complete (ID: rtb-4b30d52c)

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

This looks like it was fixed for standalone routes with aws_route but not in-line routes within aws_route_table.

Work around for now is to replace network_interface_id with instance_id.

resource "aws_route_table" "rt" {
  vpc_id = "${aws_vpc.default.id}"
    
 route {
    cidr_block           = "10.1.1.1/32"
    instance_id = "${aws_instance.server.id}"
  }
}

References

@rene00
Copy link
Author

rene00 commented Aug 17, 2017

The workaround I had proposed won't always work if the instance has multiple interfaces. Received this error today:

1 error(s) occurred:

* aws_route_table.rtb-99dccefb: 1 error(s) occurred:

* aws_route_table.rtb-99dccefb: InvalidInstanceID: There are multiple interfaces attached to instance 'i-55324f0a'. Please specify an interface ID for the operation instead.
        status code: 400, request id: 7ad4f56a-03b6-4b9a-b5cf-2d0a187f028f

@catsby catsby added the bug Addresses a defect in current functionality. label Aug 18, 2017
@catsby
Copy link
Contributor

catsby commented Aug 18, 2017

Hey @rene00 thank you for the issue and the proposed fix. We'll take a look or perhaps a community member will take a try at it

@radeksimko radeksimko added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 28, 2018
@psychoweb
Copy link

+1

Could it be possible to allow specifying both instance_id and network_interface_id when defining aws_route_table objects? Currently this behaviour fails during configuration check and, while I see a demand of consistency between the two IDs, AWS itself could give an error if the specified network interface is not attached to the relative instance.

@nevir
Copy link
Contributor

nevir commented Jun 27, 2018

Work around for now is to replace network_interface_id with instance_id.

This occurs for me when providing instance_id (and not network_interface_id), too :(

@fabiodbr
Copy link

An aws_route_table using an instance as VPN occurred diff every time for me too using an network_interface_id in the route.
The workaround was to create an aws_route separately.

resource "aws_route_table" "private" {
vpc_id = "${aws_vpc.this.id}"
}

resource "aws_route" "natgw" {
route_table_id = "${aws_route_table.private.id}"
nat_gateway_id = "${aws_nat_gateway.nat_gw.id}"
destination_cidr_block = "0.0.0.0/0"
}

resource "aws_route" "vpn" {
route_table_id = "${aws_route_table.private.id}"
network_interface_id = "${aws_instance.vpn_instance.primary_network_interface_id}"
destination_cidr_block = "10.10.0.0/22"
}

@klatiss
Copy link

klatiss commented May 21, 2019

I'm still seeing this with Terraform 0.11.14 and the latest AWS provider (2.11.0). My current workaround is to ignore route changes in a lifycycle block after initial creation. I can do this due to a somewhat static environment but it probably wont work for everyone.

@orgito
Copy link
Contributor

orgito commented Jul 2, 2019

Terraform v0.12.3 and aws provider v2.17.0 and the problem persists.

@ckabalan
Copy link

Still seeing this with Terraform v0.12.20 and the AWS Provider v2.48.0.

ewbankkit referenced this issue in ewbankkit/terraform-provider-aws Aug 8, 2020
…o_NetworkInterface_Attached' and 'TestAccAWSRouteTable_IPv4_To_NetworkInterface_TwoAttachments'.

These two tests fail as expected (#1426 and hashicorp#5745).
ewbankkit referenced this issue in ewbankkit/terraform-provider-aws Dec 7, 2020
…o_NetworkInterface_Attached' and 'TestAccAWSRouteTable_IPv4_To_NetworkInterface_TwoAttachments'.

These two tests fail as expected (#1426 and hashicorp#5745).
bflad added a commit that referenced this issue Dec 7, 2020
…ion for future fixes/enhancements (#14013)

* r/aws_route: New 'TestAccAWSRouteTable_basic'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_basic -timeout 120m
=== RUN   TestAccAWSRouteTable_basic
=== PAUSE TestAccAWSRouteTable_basic
=== CONT  TestAccAWSRouteTable_basic
--- PASS: TestAccAWSRouteTable_basic (37.78s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	37.839s

* r/aws_route: Add 'TestAccAWSRouteTable_disappears'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_disappears'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_disappears -timeout 120m
=== RUN   TestAccAWSRouteTable_disappears
=== PAUSE TestAccAWSRouteTable_disappears
=== CONT  TestAccAWSRouteTable_disappears
--- PASS: TestAccAWSRouteTable_disappears (35.58s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	35.625s

* r/aws_route: Add 'TestAccAWSRouteTable_IPv4_To_InternetGateway'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_IPv4_To_InternetGateway'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_IPv4_To_InternetGateway -timeout 120m
=== RUN   TestAccAWSRouteTable_IPv4_To_InternetGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_InternetGateway
=== CONT  TestAccAWSRouteTable_IPv4_To_InternetGateway
--- PASS: TestAccAWSRouteTable_IPv4_To_InternetGateway (78.31s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	78.372s

* r/aws_route: Update 'TestAccAWSRouteTable_tags'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_tags'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_tags -timeout 120m
=== RUN   TestAccAWSRouteTable_tags
=== PAUSE TestAccAWSRouteTable_tags
=== CONT  TestAccAWSRouteTable_tags
--- PASS: TestAccAWSRouteTable_tags (84.18s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	84.234s

* r/aws_route_table: 'TestAccAWSRouteTable_instance' -> 'TestAccAWSRouteTable_IPv4_To_Instance'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_IPv4_To_Instance'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_IPv4_To_Instance -timeout 120m
=== RUN   TestAccAWSRouteTable_IPv4_To_Instance
=== PAUSE TestAccAWSRouteTable_IPv4_To_Instance
=== CONT  TestAccAWSRouteTable_IPv4_To_Instance
--- PASS: TestAccAWSRouteTable_IPv4_To_Instance (109.73s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	109.799s

* r/aws_route_table: 'TestAccAWSRouteTable_ipv6' -> 'TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway -timeout 120m
=== RUN   TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
=== PAUSE TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
=== CONT  TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
--- PASS: TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway (41.79s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	41.826s

* r/aws_route_table: Fix 'testAccRouteTableConfigPanicEmptyRoute'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_panicEmptyRoute'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_panicEmptyRoute -timeout 120m
=== RUN   TestAccAWSRouteTable_panicEmptyRoute
=== PAUSE TestAccAWSRouteTable_panicEmptyRoute
=== CONT  TestAccAWSRouteTable_panicEmptyRoute
--- PASS: TestAccAWSRouteTable_panicEmptyRoute (24.60s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	24.636s

* r/aws_route_table: Rework 'TestAccAWSRouteTable_Route_ConfigMode'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_Route_ConfigMode'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_Route_ConfigMode -timeout 120m
=== RUN   TestAccAWSRouteTable_Route_ConfigMode
=== PAUSE TestAccAWSRouteTable_Route_ConfigMode
=== CONT  TestAccAWSRouteTable_Route_ConfigMode
--- PASS: TestAccAWSRouteTable_Route_ConfigMode (102.67s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	102.732s

* r/aws_route_table: 'TestAccAWSRouteTable_Route_TransitGatewayID' -> 'TestAccAWSRouteTable_IPv4_To_TransitGateway'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_IPv4_To_TransitGateway'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_IPv4_To_TransitGateway -timeout 120m
=== RUN   TestAccAWSRouteTable_IPv4_To_TransitGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_TransitGateway
=== CONT  TestAccAWSRouteTable_IPv4_To_TransitGateway
--- PASS: TestAccAWSRouteTable_IPv4_To_TransitGateway (338.85s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	338.907s

* r/aws_route_table: 'TestAccAWSRouteTable_vpcPeering' -> 'TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection -timeout 120m
=== RUN   TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection
=== PAUSE TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection
=== CONT  TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection
--- PASS: TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection (43.87s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	43.905s

* r/aws_route_table: Rework 'TestAccAWSRouteTable_vgwRoutePropagation'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_vgwRoutePropagation'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_vgwRoutePropagation -timeout 120m
=== RUN   TestAccAWSRouteTable_vgwRoutePropagation
=== PAUSE TestAccAWSRouteTable_vgwRoutePropagation
=== CONT  TestAccAWSRouteTable_vgwRoutePropagation
--- PASS: TestAccAWSRouteTable_vgwRoutePropagation (112.21s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	112.290s

* r/aws_route_table: Add 'TestAccAWSRouteTable_VpcMultipleCidrs_VpcEndpointAssociation'. Currently fails.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_VpcMultipleCidrs_VpcEndpointAssociation'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_VpcMultipleCidrs_VpcEndpointAssociation -timeout 120m
=== RUN   TestAccAWSRouteTable_VpcMultipleCidrs_VpcEndpointAssociation
=== PAUSE TestAccAWSRouteTable_VpcMultipleCidrs_VpcEndpointAssociation
=== CONT  TestAccAWSRouteTable_VpcMultipleCidrs_VpcEndpointAssociation
--- FAIL: TestAccAWSRouteTable_VpcMultipleCidrs_VpcEndpointAssociation (47.64s)
    testing.go:684: Step 0 error: Check failed: Check 2/7 error: Route Table has incorrect number of routes (Expected=3, Actual=2)

FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	47.694s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1

* Comment out 'TestAccAWSRouteTable_VpcMultipleCidrs_VpcEndpointAssociation'.

* r/aws_route_table: Add 'TestAccAWSRouteTable_IPv4_To_NatGateway'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_IPv4_To_NatGateway'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_IPv4_To_NatGateway -timeout 120m
=== RUN   TestAccAWSRouteTable_IPv4_To_NatGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_NatGateway
=== CONT  TestAccAWSRouteTable_IPv4_To_NatGateway
--- PASS: TestAccAWSRouteTable_IPv4_To_NatGateway (228.80s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	228.838s

* r/aws_route_table: Add 'TestAccAWSRouteTable_IPv6_To_NetworkInterface'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_IPv6_To_NetworkInterface'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_IPv6_To_NetworkInterface -timeout 120m
=== RUN   TestAccAWSRouteTable_IPv6_To_NetworkInterface
=== PAUSE TestAccAWSRouteTable_IPv6_To_NetworkInterface
=== CONT  TestAccAWSRouteTable_IPv6_To_NetworkInterface
--- PASS: TestAccAWSRouteTable_IPv6_To_NetworkInterface (48.88s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	48.917s

* r/aws_route_table: Rework 'TestAccAWSRouteTable_ConditionalCidrBlock'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_ConditionalCidrBlock'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_ConditionalCidrBlock -timeout 120m
=== RUN   TestAccAWSRouteTable_ConditionalCidrBlock
=== PAUSE TestAccAWSRouteTable_ConditionalCidrBlock
=== CONT  TestAccAWSRouteTable_ConditionalCidrBlock
--- PASS: TestAccAWSRouteTable_ConditionalCidrBlock (78.76s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	78.837s

* r/aws_route_table: Rework 'testAccCheckAWSRouteTablePropagatingVgw'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_vgwRoutePropagation'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_vgwRoutePropagation -timeout 120m
=== RUN   TestAccAWSRouteTable_vgwRoutePropagation
=== PAUSE TestAccAWSRouteTable_vgwRoutePropagation
=== CONT  TestAccAWSRouteTable_vgwRoutePropagation
--- PASS: TestAccAWSRouteTable_vgwRoutePropagation (115.39s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	115.474s

* Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 2 -run=TestAccAWSRouteTable_ -timeout 120m
=== RUN   TestAccAWSRouteTable_basic
=== PAUSE TestAccAWSRouteTable_basic
=== RUN   TestAccAWSRouteTable_disappears
=== PAUSE TestAccAWSRouteTable_disappears
=== RUN   TestAccAWSRouteTable_IPv4_To_InternetGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_InternetGateway
=== RUN   TestAccAWSRouteTable_IPv4_To_Instance
=== PAUSE TestAccAWSRouteTable_IPv4_To_Instance
=== RUN   TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
=== PAUSE TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
=== RUN   TestAccAWSRouteTable_tags
=== PAUSE TestAccAWSRouteTable_tags
=== RUN   TestAccAWSRouteTable_panicEmptyRoute
=== PAUSE TestAccAWSRouteTable_panicEmptyRoute
=== RUN   TestAccAWSRouteTable_Route_ConfigMode
=== PAUSE TestAccAWSRouteTable_Route_ConfigMode
=== RUN   TestAccAWSRouteTable_IPv4_To_TransitGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_TransitGateway
=== RUN   TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection
=== PAUSE TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection
=== RUN   TestAccAWSRouteTable_vgwRoutePropagation
=== PAUSE TestAccAWSRouteTable_vgwRoutePropagation
=== RUN   TestAccAWSRouteTable_ConditionalCidrBlock
=== PAUSE TestAccAWSRouteTable_ConditionalCidrBlock
=== RUN   TestAccAWSRouteTable_IPv4_To_NatGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_NatGateway
=== RUN   TestAccAWSRouteTable_IPv6_To_NetworkInterface
=== PAUSE TestAccAWSRouteTable_IPv6_To_NetworkInterface
=== CONT  TestAccAWSRouteTable_basic
=== CONT  TestAccAWSRouteTable_IPv4_To_TransitGateway
--- PASS: TestAccAWSRouteTable_basic (37.06s)
=== CONT  TestAccAWSRouteTable_IPv6_To_NetworkInterface
--- PASS: TestAccAWSRouteTable_IPv6_To_NetworkInterface (47.79s)
=== CONT  TestAccAWSRouteTable_IPv4_To_NatGateway
--- PASS: TestAccAWSRouteTable_IPv4_To_NatGateway (196.98s)
=== CONT  TestAccAWSRouteTable_ConditionalCidrBlock
--- PASS: TestAccAWSRouteTable_IPv4_To_TransitGateway (348.59s)
=== CONT  TestAccAWSRouteTable_vgwRoutePropagation
--- PASS: TestAccAWSRouteTable_ConditionalCidrBlock (77.19s)
=== CONT  TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection
--- PASS: TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection (44.68s)
=== CONT  TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
--- PASS: TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway (42.42s)
=== CONT  TestAccAWSRouteTable_Route_ConfigMode
--- PASS: TestAccAWSRouteTable_vgwRoutePropagation (115.86s)
=== CONT  TestAccAWSRouteTable_panicEmptyRoute
--- PASS: TestAccAWSRouteTable_panicEmptyRoute (24.55s)
=== CONT  TestAccAWSRouteTable_tags
--- PASS: TestAccAWSRouteTable_Route_ConfigMode (101.57s)
=== CONT  TestAccAWSRouteTable_IPv4_To_InternetGateway
--- PASS: TestAccAWSRouteTable_tags (83.12s)
=== CONT  TestAccAWSRouteTable_IPv4_To_Instance
--- PASS: TestAccAWSRouteTable_IPv4_To_InternetGateway (78.17s)
=== CONT  TestAccAWSRouteTable_disappears
--- PASS: TestAccAWSRouteTable_disappears (34.81s)
--- PASS: TestAccAWSRouteTable_IPv4_To_Instance (121.04s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	693.250s

* r/aws_route_table: Add (and comment out) 'TestAccAWSRouteTable_IPv4_To_NetworkInterface_Attached' and 'TestAccAWSRouteTable_IPv4_To_NetworkInterface_TwoAttachments'.

These two tests fail as expected (#1426 and #5745).

* r/aws_route_table: Add 'testAccCheckAWSRouteTableRoute'.

* r/aws_route_table: Rename 'TestAccAWSRouteTable_VpcMultipleCidrs_VpcEndpointAssociation' to 'TestAccAWSRouteTable_VpcMultipleCidrs'. Gateway VPC Endpoint routes are added asynchronously so don't attempt to test.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_VpcMultipleCidrs'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_VpcMultipleCidrs -timeout 120m
=== RUN   TestAccAWSRouteTable_VpcMultipleCidrs
=== PAUSE TestAccAWSRouteTable_VpcMultipleCidrs
=== CONT  TestAccAWSRouteTable_VpcMultipleCidrs
--- PASS: TestAccAWSRouteTable_VpcMultipleCidrs (62.16s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	62.213s

* r/aws_route_table: Add 'TestAccAWSRouteTable_VpcClassicLink'

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_VpcClassicLink'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_VpcClassicLink -timeout 120m
=== RUN   TestAccAWSRouteTable_VpcClassicLink
=== PAUSE TestAccAWSRouteTable_VpcClassicLink
=== CONT  TestAccAWSRouteTable_VpcClassicLink
--- PASS: TestAccAWSRouteTable_VpcClassicLink (38.84s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	38.888s

* r/aws_route_table: Add 'TestAccAWSRouteTable_GatewayVpcEndpoint'

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_GatewayVpcEndpoint'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_GatewayVpcEndpoint -timeout 120m
=== RUN   TestAccAWSRouteTable_GatewayVpcEndpoint
=== PAUSE TestAccAWSRouteTable_GatewayVpcEndpoint
=== CONT  TestAccAWSRouteTable_GatewayVpcEndpoint
--- PASS: TestAccAWSRouteTable_GatewayVpcEndpoint (210.60s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	210.650s

* r/aws_route_table: Add 'TestAccAWSRouteTable_disappears_SubnetAssociation'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_disappears_SubnetAssociation'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_disappears_SubnetAssociation -timeout 120m
=== RUN   TestAccAWSRouteTable_disappears_SubnetAssociation
=== PAUSE TestAccAWSRouteTable_disappears_SubnetAssociation
=== CONT  TestAccAWSRouteTable_disappears_SubnetAssociation
--- PASS: TestAccAWSRouteTable_disappears_SubnetAssociation (44.11s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	44.160s

* r/aws_route_table: Add 'TestAccAWSRouteTable_MultipleRoutes'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_MultipleRoutes'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_MultipleRoutes -timeout 120m
=== RUN   TestAccAWSRouteTable_MultipleRoutes
=== PAUSE TestAccAWSRouteTable_MultipleRoutes
=== CONT  TestAccAWSRouteTable_MultipleRoutes
--- PASS: TestAccAWSRouteTable_MultipleRoutes (191.08s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	191.139s

* r/aws_route_table: Use Amazon NAT instance AMI for instance tests.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_IPv4_To_Instance'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_IPv4_To_Instance -timeout 120m
=== RUN   TestAccAWSRouteTable_IPv4_To_Instance
=== PAUSE TestAccAWSRouteTable_IPv4_To_Instance
=== CONT  TestAccAWSRouteTable_IPv4_To_Instance
--- PASS: TestAccAWSRouteTable_IPv4_To_Instance (109.91s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	110.478s
$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_MultipleRoutes'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_MultipleRoutes -timeout 120m
=== RUN   TestAccAWSRouteTable_MultipleRoutes
=== PAUSE TestAccAWSRouteTable_MultipleRoutes
=== CONT  TestAccAWSRouteTable_MultipleRoutes
--- PASS: TestAccAWSRouteTable_MultipleRoutes (204.15s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	204.201s

* r/aws_route_table: Delete 'TestAccAWSRouteTable_IPv4_To_NetworkInterface_Attached' and 'TestAccAWSRouteTable_IPv4_To_NetworkInterface_TwoAttachments'.

If we mark `instance_id` and `network_interface_id` as both `Computed: true` in the `route` attribute's schema
then we end up having to change the associated set hash function to choose one or other of those attributes to
include in the hash and ignore the other. This means that either 'TestAccAWSRouteTable_IPv4_To_Instance' will
show continuous diffs or 'TestAccAWSRouteTable_IPv4_To_NetworkInterface_Attached' will.
The longer term solution is to remove `instance_id` as a route target as the instance's primary ENI's ID can
be used in the `network_interface_id`. This will also simplify the `aws_route` resource.

* r/aws_route_table: Use 'testAccAvailableAZsNoOptInExcludeConfig'.

* Use 'testAccAvailableAZsNoOptInDefaultExcludeConfig'.

* Fix compilation errors after rebase.

* Fix compilation errors after rebase.

* Exclude 'resource_aws_route_table_test.go' from acceptance test Terraform linting (testAccAWSRouteTableConfigMultipleRoutes).

* r/aws_route_table: Ensure no diff when expanded form of IPv6 CIDR block is used.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway -timeout 120m
=== RUN   TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
=== PAUSE TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
=== CONT  TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
--- PASS: TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway (60.43s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	60.474s

* r/aws_vpc_endpoint_route_table_association: Rename 'TestAccAWSRouteTable_Route_VpcEndpointId' to 'TestAccAWSRouteTable_IPv4_To_VpcEndpoint'.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_IPv4_To_VpcEndpoint' ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 2 -run=TestAccAWSRouteTable_IPv4_To_VpcEndpoint -timeout 120m
=== RUN   TestAccAWSRouteTable_IPv4_To_VpcEndpoint
=== PAUSE TestAccAWSRouteTable_IPv4_To_VpcEndpoint
=== CONT  TestAccAWSRouteTable_IPv4_To_VpcEndpoint
--- PASS: TestAccAWSRouteTable_IPv4_To_VpcEndpoint (410.02s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	410.081s

* r/aws_route_table: Missing commit from rebase.

* Update aws/resource_aws_route_table_test.go

Co-authored-by: Brian Flad <bflad417@gmail.com>

* Update aws/resource_aws_route_table_test.go

Co-authored-by: Brian Flad <bflad417@gmail.com>

* Update aws/resource_aws_route_table_test.go

Co-authored-by: Brian Flad <bflad417@gmail.com>

* Update aws/resource_aws_route_table_test.go

Co-authored-by: Brian Flad <bflad417@gmail.com>

* Update aws/resource_aws_route_table_test.go

Co-authored-by: Brian Flad <bflad417@gmail.com>

* r/aws_route_table: 'make fmt'.

* r/aws_route_table: Refactor 'TestAccAWSRouteTable_MultipleRoutes' so as to avoid dynamic attribute names.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_MultipleRoutes'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSRouteTable_MultipleRoutes -timeout 120m
=== RUN   TestAccAWSRouteTable_MultipleRoutes
=== PAUSE TestAccAWSRouteTable_MultipleRoutes
=== CONT  TestAccAWSRouteTable_MultipleRoutes
--- PASS: TestAccAWSRouteTable_MultipleRoutes (165.99s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	166.047s

* Fix 'terrafmt' issues.

Co-authored-by: Brian Flad <bflad417@gmail.com>
@ewbankkit
Copy link
Contributor

ewbankkit commented Jan 7, 2021

Relates to the set of issues with aws_route addressed in #16930.
This can be solved by a breaking change (removing instance_id attribute): #14197.

@sylr
Copy link
Contributor

sylr commented Jan 7, 2022

Since I've encountered this issue myself (which I deem critical in my setup) I've taken it upon myself to implement #14197, build and publish it on the terraform registry.

So for those in need of a fix for this issue you can use sylr/aws. The source code can be found at https://github.com/sylr/terraform-provider-aws/tree/v3.71.0-sylr.1.

@tullydwyer
Copy link

Still getting a perpetual diff with Terraform 1.2.1 and AWS Provider 4.24.0

@unixtastic
Copy link

Still getting this on Terraform 1.2.8 and AWS Provider 4.11.0

Can we get rid of the warning saying to use network_interface_id instead of instance_id? network_interface_id doesn't seem to be a sensible option right now.

@jtele2
Copy link

jtele2 commented Sep 20, 2022

Still get this error on Terraform 1.2.9 and AWS Provider 4.31.0.

Agree with @unixtastic - the warning is annoying, but using instance_id is the only viable option to avoid constant diffs.

@paulopatto
Copy link

Still get the error on:

terraform --version 
Terraform v1.3.7
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v4.49.0

My code basicaly:

resource "aws_eip" "nat_gateway_ip" {
  vpc = true

  tags = {
    Name = "Public IP to Privnet"
  }
}


resource "aws_nat_gateway" "nat_gateway" {
  allocation_id = aws_eip.nat_gateway_ip.id
  subnet_id     = aws_subnet.dmz.id

  tags          = {
    Name = "Private network nat gateway"
    Description = "NAT gateway 4 private instances"
  }
}


resource "aws_route_table" "internal" {
  vpc_id = aws_vpc.lab.id

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_nat_gateway.nat_gateway.id
  }

  tags = {
    Name = "Internal route table"
  }
}


resource "aws_route_table_association" "private_subnets" {
  # List of subnets created w/ count
  for_each = { for k, subnet in aws_subnet.private : k => subnet }
  
  subnet_id      = each.value.id
  route_table_id = aws_route_table.internal.id
}

And every plan or apply:

Actual Behaviour

Every time I exec plan || apply, there are modifications.

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_route_table.internal will be updated in-place
  ~ resource "aws_route_table" "internal" {
        id               = "rtb-085553f49104ea7f9"
      ~ route            = [
          - {
              - carrier_gateway_id         = ""
              - cidr_block                 = "0.0.0.0/0"
              - core_network_arn           = ""
              - destination_prefix_list_id = ""
              - egress_only_gateway_id     = ""
              - gateway_id                 = ""
              - instance_id                = ""
              - ipv6_cidr_block            = ""
              - local_gateway_id           = ""
              - nat_gateway_id             = "nat-0f5a04ec428f6e340"
              - network_interface_id       = ""
              - transit_gateway_id         = ""
              - vpc_endpoint_id            = ""
              - vpc_peering_connection_id  = ""
            },
          + {
              + carrier_gateway_id         = ""
              + cidr_block                 = "0.0.0.0/0"
              + core_network_arn           = ""
              + destination_prefix_list_id = ""
              + egress_only_gateway_id     = ""
              + gateway_id                 = "nat-0f5a04ec428f6e340"
              + instance_id                = ""
              + ipv6_cidr_block            = ""
              + local_gateway_id           = ""
              + nat_gateway_id             = ""
              + network_interface_id       = ""
              + transit_gateway_id         = ""
              + vpc_endpoint_id            = ""
              + vpc_peering_connection_id  = ""
            },
        ]
        tags             = {
            "Name" = "Tabela de rotas interna"
        }
        # (5 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Expected behaviour

No changes

@jbohmann
Copy link

@paulopatto Looks like you might be seeing that behavior for a different reason: gateway_id vs. nat_gateway_id.
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table

NOTE on gateway_id and nat_gateway_id:
The AWS API is very forgiving with these two attributes and the aws_route_table resource can be created with a NAT ID specified as a Gateway ID attribute. This will lead to a permanent diff between your configuration and statefile, as the API returns the correct parameters in the returned route table. If you're experiencing constant diffs in your aws_route_table resources, the first thing to check is whether or not you're specifying a NAT ID instead of a Gateway ID, or vice-versa.

In the route config, try changing gateway_id to nat_gateway_id:

route {
    cidr_block = "0.0.0.0/0"
    nat_gateway_id = aws_nat_gateway.nat_gateway.id
}

@MonkadelicD
Copy link

$> terraform --version
Terraform v1.4.5
on linux_amd64

  • provider registry.terraform.io/hashicorp/aws v4.46.0

This issue is very frustrating when route tables get extensive. Finding what's actually changing in the output of 'terraform plan' is very time consuming.
How has this not been resolved after being a bug since 2017?
I'll have to put a lot of work into converting route blocks within aws_route_table resource blocks to individual aws_route resource blocks as mentioned by @fabiodbr

Some mention of this issue should be included in the AWS module documentation page for "Resource: aws_route_table", instead all we have is a recommendation to use network_interface_id instead of instance_id.

@unixtastic
Copy link

Is it possible to add a warning to the aws_route_table documentation recommending against the use of in-line routes?

This should not be left as an undocumented trap for future users.

@jar-b
Copy link
Member

jar-b commented May 23, 2023

Closed by #30804, merged to main via #31392

@jar-b jar-b closed this as completed May 23, 2023
@jar-b jar-b added this to the v5.0.0 milestone May 23, 2023
@github-actions
Copy link

This functionality has been released in v5.0.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

No branches or pull requests