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

crash when importing aws_route_table #8225

Closed
drscre opened this issue Aug 16, 2016 · 14 comments · Fixed by #9686
Closed

crash when importing aws_route_table #8225

drscre opened this issue Aug 16, 2016 · 14 comments · Fixed by #9686

Comments

@drscre
Copy link

drscre commented Aug 16, 2016

Terraform v0.7.0 crashes when i try to import aws_route_table resource:
terraform import aws_route_table.private <my_route_table_id>

crash.log:
https://gist.github.com/drscre/1b7994cadb588924ce627b2487e985a9

@mitchellh
Copy link
Contributor

I can see how this is possible but unclear what exactly caused it. Do you mind showing me your AWS route table + all routes? (Properties in AWS console are good).

@drscre
Copy link
Author

drscre commented Aug 17, 2016

The original problematic route table is now gone, but it was similar to this (maybe the problem is s3 endpoint ? ):
route_table

@mitchellh
Copy link
Contributor

I feel very strongly that the S3 endpoint is it. I didn't realize that was possible. But I am pretty sure we don't handle that well at all.

@brianbianco
Copy link

brianbianco commented Aug 18, 2016

@mitchellh I run into this exact problem when using Terraform v0.7.0 and trying to import a route table that uses s3 endpoints.

Here is what my route table looks like:

screen shot 2016-08-18 at 1 43 34 pm

$ terraform import aws_route_table.public rtb-473fb622
aws_route_table.public: Importing from ID "rtb-473fb622"...
Error importing: 1 error(s) occurred:

* import aws_route_table.public (id: rtb-473fb622): unexpected EOF
panic: runtime error: invalid memory address or nil pointer dereference
2016/08/18 13:45:42 [DEBUG] plugin: terraform: [signal 0xb code=0x1 addr=0x0 pc=0x55d526]
2016/08/18 13:45:42 [DEBUG] plugin: terraform:
2016/08/18 13:45:42 [DEBUG] plugin: terraform: goroutine 104 [running]:
2016/08/18 13:45:42 [DEBUG] plugin: terraform: panic(0x2fb1ba0, 0xc8200120e0)
2016/08/18 13:45:42 [DEBUG] plugin: terraform:  /opt/go/src/runtime/panic.go:481 +0x3e6
2016/08/18 13:45:42 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/builtin/providers/aws.routeIDHash(0xc820460d80, 0xc82062eff0, 0x0, 0x0)
2016/08/18 13:45:42 [DEBUG] plugin: terraform:  /opt/gopath/src/github.com/hashicorp/terraform/builtin/providers/aws/resource_aws_route.go:362 +0xa6
2016/08/18 13:45:42 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/builtin/providers/aws.resourceAwsRouteTableImportState(0xc8204600c0, 0x253e380, 0xc820492000, 0x0, 0x0, 0x0, 0x0, 0x0)
2016/08/18 13:45:42 [DEBUG] plugin: terraform:  /opt/gopath/src/github.com/hashicorp/terraform/builtin/providers/aws/import_aws_route_table.go:48 +0xf57
2016/08/18 13:45:42 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/helper/schema.(*Provider).ImportState(0xc8203f1a40, 0xc820472640, 0xc8205c5de0, 0xc, 0x0, 0x0, 0x0, 0x0, 0x0)
2016/08/18 13:45:42 [DEBUG] plugin: terraform:  /opt/gopath/src/github.com/hashicorp/terraform/helper/schema/provider.go:254 +0x496
2016/08/18 13:45:42 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).ImportState(0xc820140ce0, 0xc820662880, 0xc820662ba0, 0x0, 0x0)
2016/08/18 13:45:42 [DEBUG] plugin: terraform:  /opt/gopath/src/github.com/hashicorp/terraform/plugin/resource_provider.go:493 +0x86
2016/08/18 13:45:42 [DEBUG] plugin: terraform: reflect.Value.call(0x2c6c4c0, 0x3650678, 0x13, 0x37c3bf8, 0x4, 0xc8206bded8, 0x3, 0x3, 0x0, 0x0, ...)
2016/08/18 13:45:42 [DEBUG] plugin: terraform:  /opt/go/src/reflect/value.go:435 +0x120d
2016/08/18 13:45:42 [DEBUG] plugin: terraform: reflect.Value.Call(0x2c6c4c0, 0x3650678, 0x13, 0xc8206bded8, 0x3, 0x3, 0x0, 0x0, 0x0)
2016/08/18 13:45:42 [DEBUG] plugin: terraform:  /opt/go/src/reflect/value.go:303 +0xb1
2016/08/18 13:45:42 [DEBUG] plugin: terraform: net/rpc.(*service).call(0xc820360500, 0xc8203604c0, 0xc8203581b8, 0xc820370300, 0xc820362140, 0x2540cc0, 0xc820662880, 0x16, 0x2540d20, 0xc820662ba0, ...)
2016/08/18 13:45:42 [DEBUG] plugin: terraform:  /opt/go/src/net/rpc/server.go:383 +0x1c2
2016/08/18 13:45:42 [DEBUG] plugin: terraform: created by net/rpc.(*Server).ServeCodec
2016/08/18 13:45:42 [DEBUG] plugin: terraform:  /opt/go/src/net/rpc/server.go:477 +0x49d
2016/08/18 13:45:42 [ERROR] root: eval: *terraform.EvalImportState, err: import aws_route_table.public (id: rtb-473fb622): unexpected EOF
2016/08/18 13:45:42 [ERROR] root: eval: *terraform.EvalSequence, err: import aws_route_table.public (id: rtb-473fb622): unexpected EOF
2016/08/18 13:45:42 [TRACE] [walkImport] Exiting eval tree: aws_route_table.public (import id: rtb-473fb622)
2016/08/18 13:45:42 [DEBUG] vertex provider.aws (close), got dep: aws_route_table.public (import id: rtb-473fb622)
2016/08/18 13:45:42 [DEBUG] plugin: /usr/local/bin/terraform: plugin process exited
2016/08/18 13:45:42 [DEBUG] plugin: waiting for all plugin processes to complete...



!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version. That
information is available on the first line of crash.log. You can also
get it by running 'terraform --version' on the command line.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Link to full crash.log

https://gist.github.com/brianbianco/53347e14a07111dd644efe0cdbc19889

Looks like it is bombing out here:

return fmt.Sprintf("r-%s%d", d.Get("route_table_id").(string), hashcode.String(*r.DestinationCidrBlock))

I decided to see what the routes for my route table look like coming out of the golang SDK. These are the routes nested inside of my route table. It could be that the S3 endpoint route uses DestinationPrefixListId instead of DestinationCidrBlock, since it looks like the routeHashID function specifically calls on hashcode.String(*r.DestinationCidrBlock), and then that would likely result in the nil pointer dereference.

      Routes: [
        {
          DestinationCidrBlock: "172.16.0.0/16",
          GatewayId: "local",
          Origin: "CreateRouteTable",
          State: "active"
        },
        {
          DestinationCidrBlock: "10.0.0.0/8",
          GatewayId: "local",
          Origin: "CreateRouteTable",
          State: "active"
        },
        {
          DestinationCidrBlock: "0.0.0.0/0",
          GatewayId: "igw-cdbe18a8",
          Origin: "CreateRoute",
          State: "active"
        },
        {
          DestinationPrefixListId: "pl-68a54001",
          GatewayId: "vpce-8ec521e7",
          Origin: "CreateRoute",
          State: "active"
        }
      ]

@catsby
Copy link
Contributor

catsby commented Aug 19, 2016

The error is coming from routeIDHash, I suspect this route

          DestinationPrefixListId: "pl-68a54001",
          GatewayId: "vpce-8ec521e7",
          Origin: "CreateRoute",
          State: "active"

does not have a DestinationCidrBlock

@brianbianco
Copy link

brianbianco commented Aug 19, 2016

@catsby Right that's what I was saying in my previous comment. The routeHashID function looks for DestinationCidrBlock but there isn't one. I tried changing the code to simply use DestinationPrefixListId if CidrBlock doesn't exist.

It looked like this

  360 // Create an ID for a route
  361 func routeIDHash(d *schema.ResourceData, r *ec2.Route) string {
~ 362   dest := r.DestinationCidrBlock
+ 363   if dest == nil {
+ 364     dest = r.DestinationPrefixListId
+ 365   }
+ 366
+ 367   return fmt.Sprintf("r-%s%d", d.Get("route_table_id").(string), hashcode.String(*dest))
  368 }

The import gets further but still ends up failing with the following:

aws_route_table.public: Importing from ID "rtb-473fb622"...
aws_route_table.public: Import complete!
  Imported aws_route_table (ID: rtb-473fb622)
  Imported aws_route (ID: r-rtb-473fb6221080289494)
  Imported aws_route (ID: r-rtb-473fb6222319287420)
  Imported aws_route_table_association (ID: rtbassoc-b129b1d4)
  Imported aws_route_table_association (ID: rtbassoc-ac29b1c9)
  Imported aws_route_table_association (ID: rtbassoc-d829b1bd)
  Imported aws_main_route_table_association (ID: rtbassoc-5529b130)
aws_route.public-1: Refreshing state... (ID: r-rtb-473fb6222319287420)
aws_route_table.public: Refreshing state... (ID: rtb-473fb622)
aws_route.public: Refreshing state... (ID: r-rtb-473fb6221080289494)
aws_main_route_table_association.public: Refreshing state... (ID: rtbassoc-5529b130)
aws_route_table_association.public-1: Refreshing state... (ID: rtbassoc-ac29b1c9)
aws_route_table_association.public: Refreshing state... (ID: rtbassoc-b129b1d4)
aws_route_table_association.public-2: Refreshing state... (ID: rtbassoc-d829b1bd)
Error importing: 1 error(s) occurred:

* import aws_route.public-1 (id: r-rtb-473fb6222319287420): Terraform detected a resource with this ID doesn't
exist. Please verify the ID is correct. You cannot import non-existent
resources using Terraform import.

I was in the process of trying to track down how imports work exactly to see if somehow its local state was calculating it's ID with a different function?

@brianbianco
Copy link

@catsby Sorry to be clear, that route doesn't have a destination cidr block because it is a route for an s3 vpc endpoint. It isn't supposed to have one, but is still a valid route.

@brianbianco
Copy link

@catsby If you are viewing the issues in email, I have edited and updated my comments a bunch which may not be coming through in email updates.

@catsby
Copy link
Contributor

catsby commented Aug 19, 2016

@brianbianco understood, thanks! We appreciate all the info, we'll dig in 😄

@brianbianco
Copy link

@catsby is there any update on the status of import issues related to route tables?

@cread
Copy link

cread commented Sep 27, 2016

I've also just had this crash with version 0.7.4.

@sammysammy
Copy link

Hi I've also just had this issue - same with 0.7.4 and 0.7.5 - also includes a VPC endpoint

@ewbankkit
Copy link
Contributor

Same in 0.7.8-dev.

@ghost
Copy link

ghost commented Apr 21, 2020

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.

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