provider/aws: Fix issue destroy Route 53 zone/record if it no longer exists

This commit is contained in:
clint shryock 2015-12-07 16:33:37 -06:00
parent d69abbaeda
commit cf87642bc8
2 changed files with 15 additions and 0 deletions

View File

@ -245,6 +245,11 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
// get expanded name // get expanded name
zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{Id: aws.String(zone)}) zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{Id: aws.String(zone)})
if err != nil { if err != nil {
if r53err, ok := err.(awserr.Error); ok && r53err.Code() == "NoSuchHostedZone" {
log.Printf("[DEBUG] No matching Route 53 Record found for: %s, removing from state file", d.Id())
d.SetId("")
return nil
}
return err return err
} }
en := expandRecordName(d.Get("name").(string), *zoneRecord.HostedZone.Name) en := expandRecordName(d.Get("name").(string), *zoneRecord.HostedZone.Name)
@ -312,6 +317,11 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er
var err error var err error
zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{Id: aws.String(zone)}) zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{Id: aws.String(zone)})
if err != nil { if err != nil {
if r53err, ok := err.(awserr.Error); ok && r53err.Code() == "NoSuchHostedZone" {
log.Printf("[DEBUG] No matching Route 53 Record found for: %s, removing from state file", d.Id())
d.SetId("")
return nil
}
return err return err
} }
// Get the records // Get the records

View File

@ -213,6 +213,11 @@ func resourceAwsRoute53ZoneDelete(d *schema.ResourceData, meta interface{}) erro
d.Get("name").(string), d.Id()) d.Get("name").(string), d.Id())
_, err := r53.DeleteHostedZone(&route53.DeleteHostedZoneInput{Id: aws.String(d.Id())}) _, err := r53.DeleteHostedZone(&route53.DeleteHostedZoneInput{Id: aws.String(d.Id())})
if err != nil { if err != nil {
if r53err, ok := err.(awserr.Error); ok && r53err.Code() == "NoSuchHostedZone" {
log.Printf("[DEBUG] No matching Route 53 Zone found for: %s, removing from state file", d.Id())
d.SetId("")
return nil
}
return err return err
} }