From 6536f0b7f224f62d30549a98ec511ada21e4a783 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Fri, 2 Jul 2021 13:34:25 +1000 Subject: [PATCH] resource/cloudflare_worker_cron_trigger: account for missing scripts If the script is removed, the associated relationships (triggers, environment variables, etc) need to be removed from the state to ensure that the dashboard behaviour of total cleanup is handled within Terraform. Closes #1120 --- cloudflare/resource_cloudflare_worker_cron_trigger.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cloudflare/resource_cloudflare_worker_cron_trigger.go b/cloudflare/resource_cloudflare_worker_cron_trigger.go index 8662535714..d3cc60966f 100644 --- a/cloudflare/resource_cloudflare_worker_cron_trigger.go +++ b/cloudflare/resource_cloudflare_worker_cron_trigger.go @@ -3,6 +3,7 @@ package cloudflare import ( "context" "fmt" + "strings" "github.com/cloudflare/cloudflare-go" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -58,6 +59,12 @@ func resourceCloudflareWorkerCronTriggerRead(d *schema.ResourceData, meta interf s, err := client.ListWorkerCronTriggers(context.Background(), scriptName) if err != nil { + // If the script is removed, we also need to remove the triggers. + if strings.Contains(err.Error(), "workers.api.error.script_not_found") { + d.SetId("") + return nil + } + return fmt.Errorf("failed to read Worker Cron Trigger: %s", err) }