Skip to content

Commit

Permalink
Merge pull request #2545 from hashicorp/b-cloudflare-not-found
Browse files Browse the repository at this point in the history
providers/cloudflare: if resource no longer exists, set ID to ""
  • Loading branch information
mitchellh committed Jun 29, 2015
2 parents 9100ad5 + 05bc835 commit b257efa
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion builtin/providers/cloudflare/resource_cloudflare_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cloudflare
import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"
"github.com/pearkes/cloudflare"
Expand Down Expand Up @@ -91,7 +92,14 @@ func resourceCloudFlareRecordRead(d *schema.ResourceData, meta interface{}) erro

rec, err := client.RetrieveRecord(d.Get("domain").(string), d.Id())
if err != nil {
return fmt.Errorf("Couldn't find CloudFlare Record ID (%s) for domain (%s): %s", d.Id(), d.Get("domain").(string), err)
if strings.Contains(err.Error(), "not found") {
d.SetId("")
return nil
}

return fmt.Errorf(
"Couldn't find CloudFlare Record ID (%s) for domain (%s): %s",
d.Id(), d.Get("domain").(string), err)
}

d.Set("name", rec.Name)
Expand Down

0 comments on commit b257efa

Please sign in to comment.