Skip to content

Disabling a Google Cloud Scheduler Job with Terraform

In this guide, we'll walk through the process of disabling a Google Cloud Scheduler job by modifying its Terraform configuration. We'll assume you have a basic understanding of Terraform and Google Cloud Scheduler.

Current Behavior

Let's say you have an existing Cloud Scheduler job that runs on a defined schedule (e.g. daily, weekly). This job executes a specific task or hits an endpoint when triggered by the schedule.

Solution

To disable the Cloud Scheduler job and prevent it from running, simply remove its configuration from your Terraform code:

  1. Open the .tf file containing the google_cloud_scheduler_job resource for the job.

  2. Find the resource block that defines the job, which looks something like this:

hcl
resource "google_cloud_scheduler_job" "example_job" {
  name        = "example-job"
  description = "Example Cloud Scheduler job"
  schedule    = "0 9 * * 1"

  http_target {
    uri = "https://example.com/endpoint"
  }
}
  1. Delete or comment out the entire resource block.

  2. Save the updated .tf file.

  3. (Optional) Run terraform apply to update your infrastructure and remove the job.

By removing the google_cloud_scheduler_job resource, you're telling Terraform to delete the corresponding Cloud Scheduler job. This change will persist across future Terraform runs, ensuring the job remains disabled.

Conclusion

Disabling a Google Cloud Scheduler job with Terraform is a straightforward process. By modifying your configuration to remove the job's resource block, you can prevent it from running without affecting the rest of your infrastructure.