Merge pull request #4179 from aberghage/bugfix/digitalocean_ignore_dns_404

Check HTTP status codes on responses from the DigitalOcean API instead of doing string compares
This commit is contained in:
Clint 2015-12-07 15:04:33 -06:00
commit c95667ce99
3 changed files with 10 additions and 12 deletions

View File

@ -3,7 +3,6 @@ package digitalocean
import ( import (
"fmt" "fmt"
"log" "log"
"strings"
"github.com/digitalocean/godo" "github.com/digitalocean/godo"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -56,11 +55,11 @@ func resourceDigitalOceanDomainCreate(d *schema.ResourceData, meta interface{})
func resourceDigitalOceanDomainRead(d *schema.ResourceData, meta interface{}) error { func resourceDigitalOceanDomainRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*godo.Client) client := meta.(*godo.Client)
domain, _, err := client.Domains.Get(d.Id()) domain, resp, err := client.Domains.Get(d.Id())
if err != nil { if err != nil {
// If the domain is somehow already destroyed, mark as // If the domain is somehow already destroyed, mark as
// successfully gone // successfully gone
if strings.Contains(err.Error(), "404 Not Found") { if resp.StatusCode == 404 {
d.SetId("") d.SetId("")
return nil return nil
} }

View File

@ -115,11 +115,11 @@ func resourceDigitalOceanRecordRead(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("invalid record ID: %v", err) return fmt.Errorf("invalid record ID: %v", err)
} }
rec, _, err := client.Domains.Record(domain, id) rec, resp, err := client.Domains.Record(domain, id)
if err != nil { if err != nil {
// If the record is somehow already destroyed, mark as // If the record is somehow already destroyed, mark as
// successfully gone // successfully gone
if strings.Contains(err.Error(), "404 Not Found") { if resp.StatusCode == 404 {
d.SetId("") d.SetId("")
return nil return nil
} }
@ -183,15 +183,15 @@ func resourceDigitalOceanRecordDelete(d *schema.ResourceData, meta interface{})
log.Printf("[INFO] Deleting record: %s, %d", domain, id) log.Printf("[INFO] Deleting record: %s, %d", domain, id)
_, err = client.Domains.DeleteRecord(domain, id) resp, delErr := client.Domains.DeleteRecord(domain, id)
if err != nil { if delErr != nil {
// If the record is somehow already destroyed, mark as // If the record is somehow already destroyed, mark as
// successfully gone // successfully gone
if strings.Contains(err.Error(), "404 Not Found") { if resp.StatusCode == 404 {
return nil return nil
} }
return fmt.Errorf("Error deleting record: %s", err) return fmt.Errorf("Error deleting record: %s", delErr)
} }
return nil return nil

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"log" "log"
"strconv" "strconv"
"strings"
"github.com/digitalocean/godo" "github.com/digitalocean/godo"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -71,11 +70,11 @@ func resourceDigitalOceanSSHKeyRead(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("invalid SSH key id: %v", err) return fmt.Errorf("invalid SSH key id: %v", err)
} }
key, _, err := client.Keys.GetByID(id) key, resp, err := client.Keys.GetByID(id)
if err != nil { if err != nil {
// If the key is somehow already destroyed, mark as // If the key is somehow already destroyed, mark as
// successfully gone // successfully gone
if strings.Contains(err.Error(), "404 Not Found") { if resp.StatusCode == 404 {
d.SetId("") d.SetId("")
return nil return nil
} }