provider/aws: Prevent Crash when importing aws_route53_record (#14218)

Fixes: #14217

We now check to make sure that we have the correct number of parts when
we have split the resource ID. It isn't an elegant fix but it works as
expected. Also added some more documentation about what is required to
actually construct the Id needed for import
This commit is contained in:
Paul Stack 2017-05-04 21:51:10 +03:00 committed by GitHub
parent 354d6b832c
commit 3bb4c56165
2 changed files with 15 additions and 2 deletions

View File

@ -460,7 +460,9 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
if _, ok := d.GetOk("zone_id"); !ok {
parts := strings.Split(d.Id(), "_")
if len(parts) == 1 {
//we check that we have parsed the id into the correct number of segments
//we need at least 3 segments!
if len(parts) == 1 || len(parts) < 3 {
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")
}

View File

@ -141,7 +141,18 @@ Weighted routing policies support the following:
## Import
Route53 Records can be imported using ID of the record, e.g.
Route53 Records can be imported using ID of the record. The ID is made up as ZONEID_RECORDNAME_TYPE_SET-IDENTIFIER
e.g.
```
Z4KAPRWWNC7JR_dev.example.com_NS_dev
```
In this example, `Z4KAPRWWNC7JR` is the ZoneID, `dev.example.com` is the Record Name, `NS` is the Type and `dev` is the Set Identifier.
Only the Set Identifier is actually optional in the ID
To import the ID above, it would look as follows:
```
$ terraform import aws_route53_record.myrecord Z4KAPRWWNC7JR_dev.example.com_NS_dev