google_cloud_scheduler_job

A scheduled job that can publish a PubSub message or an HTTP request every X interval of time, using a crontab format string.

To get more information about Job, see:

Open in Cloud Shell

Example Usage - Scheduler Job Pubsub

resource "google_pubsub_topic" "topic" {
  name = "job-topic"
}

resource "google_cloud_scheduler_job" "job" {
  name        = "test-job"
  description = "test job"
  schedule    = "*/2 * * * *"

  pubsub_target {
    # topic.id is the topic's full resource name.
    topic_name = google_pubsub_topic.topic.id
    data       = base64encode("test")
  }
}
Open in Cloud Shell

Example Usage - Scheduler Job Http

resource "google_cloud_scheduler_job" "job" {
  name             = "test-job"
  description      = "test http job"
  schedule         = "*/8 * * * *"
  time_zone        = "America/New_York"
  attempt_deadline = "320s"

  retry_config {
    retry_count = 1
  }

  http_target {
    http_method = "POST"
    uri         = "https://example.com/"
    body        = base64encode("{\"foo\":\"bar\"}")
    headers = {
      "Content-Type" = "application/json"
    }
  }
}
Open in Cloud Shell

Example Usage - Scheduler Job Paused

resource "google_cloud_scheduler_job" "job" {
  paused           = true
  name             = "test-job"
  description      = "test http job with updated fields"
  schedule         = "*/8 * * * *"
  time_zone        = "America/New_York"
  attempt_deadline = "320s"

  retry_config {
    retry_count = 1
  }

  http_target {
    http_method = "POST"
    uri         = "https://example.com/ping"
    body        = base64encode("{\"foo\":\"bar\"}")
    headers = {
      "Content-Type" = "application/json"
    }
  }
}
Open in Cloud Shell

Example Usage - Scheduler Job App Engine

resource "google_cloud_scheduler_job" "job" {
  name             = "test-job"
  schedule         = "*/4 * * * *"
  description      = "test app engine job"
  time_zone        = "Europe/London"
  attempt_deadline = "320s"

  retry_config {
    min_backoff_duration = "1s"
    max_retry_duration = "10s"
    max_doublings = 2
    retry_count = 3
  }

  app_engine_http_target {
    http_method = "POST"

    app_engine_routing {
      service  = "web"
      version  = "prod"
      instance = "my-instance-001"
    }

    relative_uri = "/ping"
  }
}
## Example Usage - Scheduler Job Oauth
data "google_compute_default_service_account" "default" {
}

resource "google_cloud_scheduler_job" "job" {
  name             = "test-job"
  description      = "test http job"
  schedule         = "*/8 * * * *"
  time_zone        = "America/New_York"
  attempt_deadline = "320s"

  http_target {
    http_method = "GET"
    uri         = "https://cloudscheduler.googleapis.com/v1/projects/my-project-name/locations/us-west1/jobs"

    oauth_token {
      service_account_email = data.google_compute_default_service_account.default.email
    }
  }
}
Open in Cloud Shell

Example Usage - Scheduler Job Oidc

data "google_compute_default_service_account" "default" {
}

resource "google_cloud_scheduler_job" "job" {
  name             = "test-job"
  description      = "test http job"
  schedule         = "*/8 * * * *"
  time_zone        = "America/New_York"
  attempt_deadline = "320s"

  http_target {
    http_method = "GET"
    uri         = "https://example.com/ping"

    oidc_token {
      service_account_email = data.google_compute_default_service_account.default.email
    }
  }
}

Argument Reference

The following arguments are supported:


The retry_config block supports:

The pubsub_target block supports:

The app_engine_http_target block supports:

The app_engine_routing block supports:

The http_target block supports:

The oauth_token block supports:

The oidc_token block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

Job can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import Job using one of the formats above. For example:

import {
  id = "projects/{{project}}/locations/{{region}}/jobs/{{name}}"
  to = google_cloud_scheduler_job.default
}

When using the terraform import command, Job can be imported using one of the formats above. For example:

$ terraform import google_cloud_scheduler_job.default projects/{{project}}/locations/{{region}}/jobs/{{name}}
$ terraform import google_cloud_scheduler_job.default {{project}}/{{region}}/{{name}}
$ terraform import google_cloud_scheduler_job.default {{region}}/{{name}}
$ terraform import google_cloud_scheduler_job.default {{name}}

User Project Overrides

This resource supports User Project Overrides.