providers/cloudflare: if resource no longer exists, set ID to ""

[GH-301]
This commit is contained in:
Mitchell Hashimoto 2015-06-28 23:28:12 -07:00
parent da1cac623d
commit 05bc835748
1 changed files with 9 additions and 1 deletions

View File

@ -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)