Merge pull request #2545 from hashicorp/b-cloudflare-not-found
providers/cloudflare: if resource no longer exists, set ID to ""
This commit is contained in:
commit
b257efa51a
|
@ -3,6 +3,7 @@ package cloudflare
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/pearkes/cloudflare"
|
"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())
|
rec, err := client.RetrieveRecord(d.Get("domain").(string), d.Id())
|
||||||
if err != nil {
|
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)
|
d.Set("name", rec.Name)
|
||||||
|
|
Loading…
Reference in New Issue