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

provider/aws: Support import of Route53 records with underscores. #14466

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions builtin/providers/aws/resource_aws_route53_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"regexp"
"strings"
"time"

Expand All @@ -20,6 +21,7 @@ import (

var r53NoRecordsFound = errors.New("No matching Hosted Zone found")
var r53NoHostedZoneFound = errors.New("No matching records found")
var r53ValidRecordTypes = regexp.MustCompile("^(AAAA|A|NS|SOA|SPF|MX|PTR|CNAME|TXT|SRV|NAPTR)$")

func resourceAwsRoute53Record() *schema.Resource {
return &schema.Resource{
Expand Down Expand Up @@ -466,11 +468,20 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
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])
if len(parts) > 3 {
d.Set("set_identifier", parts[3])
//attempt to determine if there is a set_identifier
// this is complicated by domains which contain underscores
last := parts[len(parts)-1]
if len(parts) == 3 || r53ValidRecordTypes.MatchString(last) {
//no set identifier
d.Set("zone_id", parts[0])
d.Set("name", parts[1:len(parts)-1])
d.Set("type", last)
} else {
//possible set identifier
d.Set("zone_id", parts[0])
d.Set("name", parts[1:len(parts)-2])
d.Set("type", parts[len(parts)-2])
d.Set("set_identifier", last)
}
}

Expand Down