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

Import of Route 53 A record crashing TF #11549

Closed
westredd opened this issue Jan 31, 2017 · 5 comments · Fixed by #11603
Closed

Import of Route 53 A record crashing TF #11549

westredd opened this issue Jan 31, 2017 · 5 comments · Fixed by #11603
Assignees

Comments

@westredd
Copy link

westredd commented Jan 31, 2017

Terraform Version

0.8.5

Affected Resource(s)

Please list the resources as a list, for example:

  • aws_route53_record

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

NA - I am only running the import command on a route53 DNA A record

Debug Output

https://gist.github.com/westredd/c0f5145de05f3a2abe250919803016d3

Panic Output

https://gist.github.com/westredd/51661fbcb85ed0755d801a7a80ce6172

Expected Behavior

DNS record should have appeared in state file after running the import command

Actual Behavior

Terraform Crash

Steps to Reproduce

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

  1. Create an A record manually in a Route53 public hosted zone (the zone is not the authoritative zone)
  2. Attempt to import it using the following command: terraform import aws_route53_record.import1 test.example.com

Important Factoids

The DNS zone was created for testing. It is not a registered domain .

References

NA

@stack72
Copy link
Contributor

stack72 commented Feb 1, 2017

Hi @westredd

thanks for getting in touch here. Sorry this is an issue for you. I have just spent some time on this crash. Unfortunately, it's not a nice user experience I'm afraid. I ran the config as follows (please excuse using the domain in your crash report)

provider "aws" {
    region = "us-west-2"
}

resource "aws_route53_zone" "main" {
	name = "westredd.com"
}

resource "aws_route53_record" "default" {
	zone_id = "${aws_route53_zone.main.zone_id}"
	name = "mike"
	type = "A"
	ttl = "30"
	records = ["127.0.0.1"]
}

That gave me the correct configuration to start with. I then tried exactly what you did:

% terraform import aws_route53_record.import1 mike.westredd.com                                                                              ✭
aws_route53_record.import1: Importing from ID "mike.westredd.com"...
aws_route53_record.import1: Import complete!
  Imported aws_route53_record (ID: mike.westredd.com)
aws_route53_record.import1: Refreshing state... (ID: mike.westredd.com)
Error importing: 1 error(s) occurred:

* aws_route53_record.import1: unexpected EOF
panic: runtime error: index out of range

From looking at the code, I wish it were that simple to run an import :(

I was able to get it working as follows:

% terraform import aws_route53_record.import1 Z3M232P8A7JAIH_mike_A                                                                      1 ↵ ✭
aws_route53_record.import1: Importing from ID "Z3M232P8A7JAIH_mike_A"...
aws_route53_record.import1: Import complete!
  Imported aws_route53_record (ID: Z3M232P8A7JAIH_mike_A)
aws_route53_record.import1: Refreshing state... (ID: Z3M232P8A7JAIH_mike_A)

Import success! The resources imported are shown above. These are
now in your Terraform state. Import does not currently generate
configuration, so you must do this next. If you do not create configuration
for the above resources, then the next `terraform plan` will mark
them for destruction.

I could then terraform show based on this to get your record:

% terraform show                                                                                                                             ✭
aws_route53_record.import1:
  id = Z3M232P8A7JAIH_mike_A
  fqdn = mike.westredd.com
  health_check_id =
  name = mike
  records.# = 1
  records.3619153832 = 127.0.0.1
  set_identifier =
  ttl = 30
  type = A
  weight = -1
  zone_id = Z3M232P8A7JAIH

So the documentation isn't very clear in this area - we need to make this much much better! The format of what I imported was as follows:

Z3M232P8A7JAIH      <----------- THIS IS THE ZONE_ID
mike                            <----------- THIS IS THE RECORD NAME
A                                 <----------- THIS IS THE RECORD TYPE

We need all of these 3 things to be able to import a record. Each need to be delimited by _ - as I said, this isn't a great user experience.

Now, for the crash itself. This should never happen! We should have been able to parse that string that you sent us and threw the appropriate error to you suggesting what you need to do

I am going to suggest that I throw an error in this area if the import isn't correct. How about something like this?

% terraform import aws_route53_record.import mike.westredd.com
aws_route53_record.import: Importing from ID "mike.westredd.com"...
aws_route53_record.import: Import complete!
  Imported aws_route53_record (ID: mike.westredd.com)
aws_route53_record.import: Refreshing state... (ID: mike.westredd.com)
Error importing: 1 error(s) occurred:

* aws_route53_record.import: Error Importing aws_route_53 record. Please make sure the record ID is in the form ZONEID_RECORDNAME_TYPE (i.e. Z4KAPRWWNC7JR_dev_A

Would this help?

Paul

@stack72 stack72 self-assigned this Feb 1, 2017
stack72 added a commit that referenced this issue Feb 1, 2017
Fixes: #11549

When a user passes the wrong argument to a route53_record import, they
got a crash. This was because we expected the ID to parse correctly. The
crash looked like this:

```
% terraform import aws_route53_record.import1 mike.westredd.com
aws_route53_record.import1: Importing from ID "mike.westredd.com"...
aws_route53_record.import1: Import complete!
  Imported aws_route53_record (ID: mike.westredd.com)
aws_route53_record.import1: Refreshing state... (ID: mike.westredd.com)
Error importing: 1 error(s) occurred:

* aws_route53_record.import1: unexpected EOF
panic: runtime error: index out of range
```

Rather than throwing a panic to the user, we should present them with a more useful message that tells them what the error is:

```
% terraform import aws_route53_record.import mike.westredd.com
aws_route53_record.import: Importing from ID "mike.westredd.com"...
aws_route53_record.import: Import complete!
  Imported aws_route53_record (ID: mike.westredd.com)
aws_route53_record.import: Refreshing state... (ID: mike.westredd.com)
Error importing: 1 error(s) occurred:

* aws_route53_record.import: Error Importing aws_route_53 record. Please make sure the record ID is in the form ZONEID_RECORDNAME_TYPE (i.e. Z4KAPRWWNC7JR_dev_A
```

At least they can work out what the problem is in this case
stack72 added a commit that referenced this issue Feb 1, 2017
Fixes: #11549

When a user passes the wrong argument to a route53_record import, they
got a crash. This was because we expected the ID to parse correctly. The
crash looked like this:

```
% terraform import aws_route53_record.import1 mike.westredd.com
aws_route53_record.import1: Importing from ID "mike.westredd.com"...
aws_route53_record.import1: Import complete!
  Imported aws_route53_record (ID: mike.westredd.com)
aws_route53_record.import1: Refreshing state... (ID: mike.westredd.com)
Error importing: 1 error(s) occurred:

* aws_route53_record.import1: unexpected EOF
panic: runtime error: index out of range
```

Rather than throwing a panic to the user, we should present them with a more useful message that tells them what the error is:

```
% terraform import aws_route53_record.import mike.westredd.com
aws_route53_record.import: Importing from ID "mike.westredd.com"...
aws_route53_record.import: Import complete!
  Imported aws_route53_record (ID: mike.westredd.com)
aws_route53_record.import: Refreshing state... (ID: mike.westredd.com)
Error importing: 1 error(s) occurred:

* aws_route53_record.import: Error Importing aws_route_53 record. Please make sure the record ID is in the form ZONEID_RECORDNAME_TYPE (i.e. Z4KAPRWWNC7JR_dev_A
```

At least they can work out what the problem is in this case
stack72 added a commit that referenced this issue Feb 1, 2017
Fixes: #11549

When a user passes the wrong argument to a route53_record import, they
got a crash. This was because we expected the ID to parse correctly. The
crash looked like this:

```
% terraform import aws_route53_record.import1 mike.westredd.com
aws_route53_record.import1: Importing from ID "mike.westredd.com"...
aws_route53_record.import1: Import complete!
  Imported aws_route53_record (ID: mike.westredd.com)
aws_route53_record.import1: Refreshing state... (ID: mike.westredd.com)
Error importing: 1 error(s) occurred:

* aws_route53_record.import1: unexpected EOF
panic: runtime error: index out of range
```

Rather than throwing a panic to the user, we should present them with a more useful message that tells them what the error is:

```
% terraform import aws_route53_record.import mike.westredd.com
aws_route53_record.import: Importing from ID "mike.westredd.com"...
aws_route53_record.import: Import complete!
  Imported aws_route53_record (ID: mike.westredd.com)
aws_route53_record.import: Refreshing state... (ID: mike.westredd.com)
Error importing: 1 error(s) occurred:

* aws_route53_record.import: Error Importing aws_route_53 record. Please make sure the record ID is in the form ZONEID_RECORDNAME_TYPE (i.e. Z4KAPRWWNC7JR_dev_A
```

At least they can work out what the problem is in this case
@westredd
Copy link
Author

westredd commented Feb 1, 2017

that's awesome help , thanks alot buddy
Yes the error you proposed would be super helpful to realise the problem
I will try this tomorrow.

arcadiatea pushed a commit to ticketmaster/terraform that referenced this issue Feb 9, 2017
…1603)

Fixes: hashicorp#11549

When a user passes the wrong argument to a route53_record import, they
got a crash. This was because we expected the ID to parse correctly. The
crash looked like this:

```
% terraform import aws_route53_record.import1 mike.westredd.com
aws_route53_record.import1: Importing from ID "mike.westredd.com"...
aws_route53_record.import1: Import complete!
  Imported aws_route53_record (ID: mike.westredd.com)
aws_route53_record.import1: Refreshing state... (ID: mike.westredd.com)
Error importing: 1 error(s) occurred:

* aws_route53_record.import1: unexpected EOF
panic: runtime error: index out of range
```

Rather than throwing a panic to the user, we should present them with a more useful message that tells them what the error is:

```
% terraform import aws_route53_record.import mike.westredd.com
aws_route53_record.import: Importing from ID "mike.westredd.com"...
aws_route53_record.import: Import complete!
  Imported aws_route53_record (ID: mike.westredd.com)
aws_route53_record.import: Refreshing state... (ID: mike.westredd.com)
Error importing: 1 error(s) occurred:

* aws_route53_record.import: Error Importing aws_route_53 record. Please make sure the record ID is in the form ZONEID_RECORDNAME_TYPE (i.e. Z4KAPRWWNC7JR_dev_A
```

At least they can work out what the problem is in this case
@pmacdougall
Copy link

@stack72 Any chance we could get the explanation of the record ID format in the documentation for aws_route53_record ?

I don't understand the import example that is currently given in the doc because there is a 4th field at the end which is not covered in your explanation above: Z4KAPRWWNC7JR_dev.example.com_NS_dev

I see that this is an NS record but what does dev signify?

@MAS150MD200
Copy link

dev - it is "set id"

@ghost
Copy link

ghost commented Apr 13, 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 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants