Skip to content

Commit

Permalink
resource/cloudflare_worker_cron_trigger: account for missing scripts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jacobbednarz committed Jul 2, 2021
1 parent be8ee61 commit 6536f0b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cloudflare/resource_cloudflare_worker_cron_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cloudflare
import (
"context"
"fmt"
"strings"

"github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 6536f0b

Please sign in to comment.