From 05bc8357480612294735981d2defc001a35d93c9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 28 Jun 2015 23:28:12 -0700 Subject: [PATCH] providers/cloudflare: if resource no longer exists, set ID to "" [GH-301] --- .../providers/cloudflare/resource_cloudflare_record.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin/providers/cloudflare/resource_cloudflare_record.go b/builtin/providers/cloudflare/resource_cloudflare_record.go index 3ffcd01d7..03f3c00eb 100644 --- a/builtin/providers/cloudflare/resource_cloudflare_record.go +++ b/builtin/providers/cloudflare/resource_cloudflare_record.go @@ -3,6 +3,7 @@ package cloudflare import ( "fmt" "log" + "strings" "github.com/hashicorp/terraform/helper/schema" "github.com/pearkes/cloudflare" @@ -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)