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

Updating network_interface_id in aws_route fails #2270

Closed
lethalpaga opened this issue Nov 14, 2017 · 13 comments · Fixed by #5657, #5687 or #16930
Closed

Updating network_interface_id in aws_route fails #2270

lethalpaga opened this issue Nov 14, 2017 · 13 comments · Fixed by #5657, #5687 or #16930
Assignees
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@lethalpaga
Copy link

Terraform Version

Terraform v0.10.8
provider.aws 1.2.0

Affected Resource(s)

  • aws_route

Terraform Configuration Files

Config 1:

provider "aws" {
  version             = "~>1.2.0"
}

resource "aws_route" "route_to_eni" {
  route_table_id         = "rtb-ba9acbbb"
  destination_cidr_block = "1.2.3.0/24"

  network_interface_id = "eni-35cadddd"
}

Config 2 (updated network_interface_id):

provider "aws" {
  version             = "~>1.2.0"
}

resource "aws_route" "route_to_eni" {
  route_table_id         = "rtb-ba9acbbb"
  destination_cidr_block = "1.2.3.0/24"

  network_interface_id = "eni-35cadddd"
}

Debug Output

https://gist.github.com/lethalpaga/28714fe7180b2debce09489c77ba1556

Expected Behavior

The route should have been updated with the new ENI id

Actual Behavior

The apply fails with

* aws_route.route_to_eni: InvalidInstanceID: There are multiple interfaces attached to instance 'i-0ec77fe2cdde1'. Please specify an interface ID for the operation instead.
	status code: 400, request id: 060b4661-c5e8-4254-92c0-ac1d13f21df7

Steps to Reproduce

  1. terraform apply with config1 to create the route
  2. terraform apply with config2 to attempt updating it

Important Factoids

  • The route creation works fine. Updating it fails.
  • In both config1 and config2 the ENI is attached to an instance that has 2 network interfaces attached.

References

@raylu-stripe
Copy link
Contributor

this bug is caused by hashicorp/terraform#7686

@paddycarver paddycarver added the bug Addresses a defect in current functionality. label Nov 21, 2017
@radeksimko radeksimko added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 28, 2018
@YakDriver
Copy link
Member

YakDriver commented Aug 25, 2018

I was able to successfully update a route using new aws_route import ability in PR #5657 . The steps I took were as follows:

  1. Create route
  2. Import the route with a new config
  3. Apply

Terraform properly updated the route resource and I verified that the change occurred in AWS.

Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  ~ aws_route.internal-default-route
      network_interface_id: "eni-0b5793f41da64217d" => "eni-07b3859117af14835"

Plan: 0 to add, 1 to change, 0 to destroy.
...
aws_route.internal-default-route: Modifying... (ID: r-rtb-091e53b115437114d_124.0.0.0/16)
  network_interface_id: "eni-0b5793f41da64217d" => "eni-07b3859117af14835"
aws_route.internal-default-route: Modifications complete after 1s (ID: r-rtb-091e53b115437114d_124.0.0.0/16)

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

@bflad
Copy link
Contributor

bflad commented Aug 30, 2018

Sorry this was set to close with a recently merged pull request. I think we should specifically write an acceptance test that ensures updating an aws_route network_interface_id that points to an aws_instance with two network interfaces updates correctly to verify this as closed.

@bflad bflad reopened this Aug 30, 2018
@kellersyf
Copy link

kellersyf commented Jul 18, 2019

I'm not sure why this was closed with the PRs affecting route imports. That appears to be an unrelated issue?

This problem still exists. If I create a route with a next-hop of an ENI, and then later change the ENI that the route points to, I get the error mentioned in this issue.

Original resource:

resource "aws_route" "my_route" {
    route_table_id = aws_route_table.my_route_table.id
    destination_cidr_block = "0.0.0.0/0"
    network_interface_id = aws_network_interface.primary_eni.id

Updated resource:

resource "aws_route" "my_route" {
    route_table_id = aws_route_table.my_route_table.id
    destination_cidr_block = "0.0.0.0/0"
    network_interface_id = aws_network_interface.secondary_eni.id

Results in this:

Error: InvalidInstanceID: There are multiple interfaces attached to instance 'i-xxxxxxxxxxxxxxxx'. Please specify an interface ID for the operation instead.

I can manually taint the resource and it replaces without issue.

Let me know what other information I can provide to help remedy this. Thanks!

@jonathanhle
Copy link

I'm not sure why this was closed with the PRs affecting route imports. That appears to be an unrelated issue?

This problem still exists. If I create a route with a next-hop of an ENI, and then later change the ENI that the route points to, I get the error mentioned in this issue.

Original resource:

resource "aws_route" "my_route" {
    route_table_id = aws_route_table.my_route_table.id
    destination_cidr_block = "0.0.0.0/0"
    network_interface_id = aws_network_interface.primary_eni.id

Updated resource:

resource "aws_route" "my_route" {
    route_table_id = aws_route_table.my_route_table.id
    destination_cidr_block = "0.0.0.0/0"
    network_interface_id = aws_network_interface.secondary_eni.id

Results in this:

Error: InvalidInstanceID: There are multiple interfaces attached to instance 'i-xxxxxxxxxxxxxxxx'. Please specify an interface ID for the operation instead.

I can manually taint the resource and it replaces without issue.

Let me know what other information I can provide to help remedy this. Thanks!

Yeah - I'm getting the same thing with 11.14 TFE. I opened a support ticket. Maybe they'll reopen this.

@nywilken
Copy link
Contributor

hi @kellersyf @jonathanhle I'm going to reopen this issue as I don't see any evidence of the fix in the merged PRs, along with the fact that folks are still seeing this error. In order to best help could we get a sample configuration with the instance resource included that is generating this error?

Have you tired running your configuration in 0.12.10 with the latest provider? If so are you running into the same issue?

@nywilken nywilken reopened this Oct 11, 2019
@nywilken nywilken added the waiting-response Maintainers are waiting on response from community or contributor. label Oct 11, 2019
@sorah
Copy link

sorah commented Oct 14, 2019

I just face this issue on Terraform v0.12.10 + provider.aws v2.32.0.

  1. Create aws_route with network_interface_id, apply
  2. Have a different EC2 instance with multiple ENIs
  3. Change network_interface_id of aws_route (1) with an ENI of instance (2), apply

(3) fails with the error mentioned in this issue.


c572134 changed instance_id to always take precedence over network_instance_id and guessing this is the cause. The list differs between resourceAwsRouteUpdate and resourceAwsRouteCreate. But reverting this doesn't fix (then it starts failing updating routes with instance_id).

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Oct 14, 2019
@sorah
Copy link

sorah commented Oct 14, 2019

I expect terraform sends UpdateRoute request with NetworkInterfaceID, but actually it sends InstanceID always.

@kellersyf
Copy link

Is it possible to just do a straight-up replace of the routes when they're updated? Is there any benefit in doing an in-place change vs a remove/re-create of the route? That would solve pretty much all your cases for updating, and the API call is very quick.

@jonathanhle
Copy link

hi @kellersyf @jonathanhle I'm going to reopen this issue as I don't see any evidence of the fix in the merged PRs, along with the fact that folks are still seeing this error. In order to best help could we get a sample configuration with the instance resource included that is generating this error?

Have you tired running your configuration in 0.12.10 with the latest provider? If so are you running into the same issue?

Unfortunately, can't move my code base to 0.12.10 yet. Have only tried the above on 0.11.14.

@don-code
Copy link

Switching routes over to another ENI is part of an automated failover process I'm working on, so as a workaround I run a one-liner before doing so that taints every route that's changing. In the interest of sharing:

terraform plan | grep '~ .*aws_route\.' | sed -E -e 's/  ~ /terraform taint /' -e 's/module\.(.*).aws_route/-module \1 aws_route/' -e 's/\[/./' -e 's/]//'

...which produces output like:

terraform taint -module cisco aws_route.public.0 
terraform taint -module cisco aws_route.public.1 
terraform taint aws_route.vpn-public.1 
terraform taint aws_route.vpn-public.2 
terraform taint aws_route.vpn-private

Explanation:

  1. Make a plan.
  2. Filter out only the routes that are changing.
  3. Change the move sigil to terraform taint.
  4. If the route is part of a module, add it to the -module flag. (Note that this will not work for routes in nested modules. I don't have any, so someone else can cross that bridge when they come to it.)
  5. If the route is looped over using count, change the [n] suffix of the resource identifier to the .n suffix that taint wants.

ewbankkit added a commit to ewbankkit/terraform-provider-aws that referenced this issue Jul 10, 2020
…ents' to test route to 2 ENIs attached to the same instance (hashicorp#2270).

Acceptance test output (failure expected):

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments -timeout 120m
=== RUN   TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== PAUSE TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== CONT  TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
--- FAIL: TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments (127.29s)
    testing.go:684: Step 1 error: errors during apply:

        Error: InvalidInstanceID: There are multiple interfaces attached to instance 'i-005065eb4850f01a4'. Please specify an interface ID for the operation instead.
        	status code: 400, request id: f601a6af-729a-4830-835b-be8887b0c3ee

          on /tmp/tf-test358593801/main.tf line 98:
          (source code not available)

FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	127.347s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1
ewbankkit added a commit to ewbankkit/terraform-provider-aws that referenced this issue Aug 9, 2020
…ents' to test route to 2 ENIs attached to the same instance (hashicorp#2270).

Acceptance test output (failure expected):

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments -timeout 120m
=== RUN   TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== PAUSE TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== CONT  TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
--- FAIL: TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments (127.29s)
    testing.go:684: Step 1 error: errors during apply:

        Error: InvalidInstanceID: There are multiple interfaces attached to instance 'i-005065eb4850f01a4'. Please specify an interface ID for the operation instead.
        	status code: 400, request id: f601a6af-729a-4830-835b-be8887b0c3ee

          on /tmp/tf-test358593801/main.tf line 98:
          (source code not available)

FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	127.347s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1
ewbankkit added a commit to ewbankkit/terraform-provider-aws that referenced this issue Aug 22, 2020
…ents' to test route to 2 ENIs attached to the same instance (hashicorp#2270).

Acceptance test output (failure expected):

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments -timeout 120m
=== RUN   TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== PAUSE TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== CONT  TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
--- FAIL: TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments (127.29s)
    testing.go:684: Step 1 error: errors during apply:

        Error: InvalidInstanceID: There are multiple interfaces attached to instance 'i-005065eb4850f01a4'. Please specify an interface ID for the operation instead.
        	status code: 400, request id: f601a6af-729a-4830-835b-be8887b0c3ee

          on /tmp/tf-test358593801/main.tf line 98:
          (source code not available)

FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	127.347s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1
ewbankkit added a commit to ewbankkit/terraform-provider-aws that referenced this issue Sep 4, 2020
…ents' to test route to 2 ENIs attached to the same instance (hashicorp#2270).

Acceptance test output (failure expected):

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments -timeout 120m
=== RUN   TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== PAUSE TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== CONT  TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
--- FAIL: TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments (127.29s)
    testing.go:684: Step 1 error: errors during apply:

        Error: InvalidInstanceID: There are multiple interfaces attached to instance 'i-005065eb4850f01a4'. Please specify an interface ID for the operation instead.
        	status code: 400, request id: f601a6af-729a-4830-835b-be8887b0c3ee

          on /tmp/tf-test358593801/main.tf line 98:
          (source code not available)

FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	127.347s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1
ewbankkit added a commit to ewbankkit/terraform-provider-aws that referenced this issue Oct 18, 2020
…ents' to test route to 2 ENIs attached to the same instance (hashicorp#2270).

Acceptance test output (failure expected):

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments -timeout 120m
=== RUN   TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== PAUSE TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== CONT  TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
--- FAIL: TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments (127.29s)
    testing.go:684: Step 1 error: errors during apply:

        Error: InvalidInstanceID: There are multiple interfaces attached to instance 'i-005065eb4850f01a4'. Please specify an interface ID for the operation instead.
        	status code: 400, request id: f601a6af-729a-4830-835b-be8887b0c3ee

          on /tmp/tf-test358593801/main.tf line 98:
          (source code not available)

FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	127.347s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1
ewbankkit added a commit to ewbankkit/terraform-provider-aws that referenced this issue Nov 15, 2020
…ents' to test route to 2 ENIs attached to the same instance (hashicorp#2270).

Acceptance test output (failure expected):

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments -timeout 120m
=== RUN   TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== PAUSE TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
=== CONT  TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments
--- FAIL: TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments (127.29s)
    testing.go:684: Step 1 error: errors during apply:

        Error: InvalidInstanceID: There are multiple interfaces attached to instance 'i-005065eb4850f01a4'. Please specify an interface ID for the operation instead.
        	status code: 400, request id: f601a6af-729a-4830-835b-be8887b0c3ee

          on /tmp/tf-test358593801/main.tf line 98:
          (source code not available)

FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	127.347s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1
@YakDriver YakDriver added this to the v3.34.0 milestone Mar 25, 2021
@YakDriver YakDriver self-assigned this Mar 25, 2021
@ghost
Copy link

ghost commented Mar 26, 2021

This has been released in version 3.34.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 for triage. Thanks!

@ghost
Copy link

ghost commented Apr 25, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.