From 50fe7e1bb0695eaa5f1c15f3a5c313d67926e1b1 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Wed, 1 Feb 2017 14:15:08 +0000 Subject: [PATCH] provider/aws: aws_route53_record import error processing (#11603) 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 --- builtin/providers/aws/resource_aws_route53_record.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/providers/aws/resource_aws_route53_record.go b/builtin/providers/aws/resource_aws_route53_record.go index 4a7f3fefe..873914193 100644 --- a/builtin/providers/aws/resource_aws_route53_record.go +++ b/builtin/providers/aws/resource_aws_route53_record.go @@ -459,6 +459,11 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro // If we don't have a zone ID we're doing an import. Parse it from the ID. if _, ok := d.GetOk("zone_id"); !ok { parts := strings.Split(d.Id(), "_") + + if len(parts) == 1 { + return fmt.Errorf("Error Importing aws_route_53 record. Please make sure the record ID is in the form ZONEID_RECORDNAME_TYPE (i.e. Z4KAPRWWNC7JR_dev_A") + } + d.Set("zone_id", parts[0]) d.Set("name", parts[1]) d.Set("type", parts[2])