From 190e28ccf76c18822a73ad65fa158eb25379a57e Mon Sep 17 00:00:00 2001 From: Tylor Stewart Date: Thu, 10 Sep 2020 22:05:02 +1000 Subject: [PATCH 1/2] set logpush job id to "" when not found --- cloudflare/resource_cloudflare_logpush_job.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cloudflare/resource_cloudflare_logpush_job.go b/cloudflare/resource_cloudflare_logpush_job.go index 2ff8921cd8..7ff7f95085 100644 --- a/cloudflare/resource_cloudflare_logpush_job.go +++ b/cloudflare/resource_cloudflare_logpush_job.go @@ -90,6 +90,7 @@ func resourceCloudflareLogpushJobRead(d *schema.ResourceData, meta interface{}) if err != nil { if strings.Contains(err.Error(), "404") { log.Printf("[INFO] Could not find LogpushJob with id: %q", jobID) + d.SetId("") return nil } return fmt.Errorf("error finding logpush job %q: %s", jobID, err) From 19f0c59f15a95f37e277959887a4093a1fbb06a3 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Fri, 18 Sep 2020 07:58:35 +1000 Subject: [PATCH 2/2] Handle missing `ID` in `Delete` Should someone delete a resource outside of Terraform, it won't be found when the remote delete is called. Instead of throwing an error stating we couldn't find it, just remove it from the state. Fixes #795 --- cloudflare/resource_cloudflare_logpush_job.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cloudflare/resource_cloudflare_logpush_job.go b/cloudflare/resource_cloudflare_logpush_job.go index 7ff7f95085..c9c065d654 100644 --- a/cloudflare/resource_cloudflare_logpush_job.go +++ b/cloudflare/resource_cloudflare_logpush_job.go @@ -164,10 +164,17 @@ func resourceCloudflareLogpushJobDelete(d *schema.ResourceData, meta interface{} deleteErr := client.DeleteLogpushJob(d.Get("zone_id").(string), job.ID) if deleteErr != nil { + if strings.Contains(err.Error(), "job not found") { + log.Printf("[INFO] Could not find logpush job with id: %q", job.ID) + d.SetId("") + return nil + } return fmt.Errorf("error deleting logpush job: %+v", job.ID) } - return resourceCloudflareLogpushJobRead(d, meta) + d.SetId("") + + return nil } func resourceCloudflareLogpushJobImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {