Skip to content

googleCloudSchedulerJob

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:

Example Usage - Scheduler Job Pubsub

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googlePubsubTopicTopic = new google.pubsubTopic.PubsubTopic(
  this,
  "topic",
  {
    name: "job-topic",
  }
);
new google.cloudSchedulerJob.CloudSchedulerJob(this, "job", {
  description: "test job",
  name: "test-job",
  pubsub_target: [
    {
      data: '${base64encode("test")}',
      topic_name: googlePubsubTopicTopic.id,
    },
  ],
  schedule: "*/2 * * * *",
});

Example Usage - Scheduler Job Http

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudSchedulerJob.CloudSchedulerJob(this, "job", {
  attempt_deadline: "320s",
  description: "test http job",
  http_target: [
    {
      body: '${base64encode("{\\"foo\\":\\"bar\\"}")}',
      http_method: "POST",
      uri: "https://example.com/",
    },
  ],
  name: "test-job",
  retry_config: [
    {
      retry_count: 1,
    },
  ],
  schedule: "*/8 * * * *",
  time_zone: "America/New_York",
});

Example Usage - Scheduler Job Paused

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudSchedulerJob.CloudSchedulerJob(this, "job", {
  attempt_deadline: "320s",
  description: "test http job with updated fields",
  http_target: [
    {
      body: '${base64encode("{\\"foo\\":\\"bar\\"}")}',
      http_method: "POST",
      uri: "https://example.com/ping",
    },
  ],
  name: "test-job",
  paused: true,
  retry_config: [
    {
      retry_count: 1,
    },
  ],
  schedule: "*/8 * * * *",
  time_zone: "America/New_York",
});

Example Usage - Scheduler Job App Engine

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudSchedulerJob.CloudSchedulerJob(this, "job", {
  app_engine_http_target: [
    {
      app_engine_routing: [
        {
          instance: "my-instance-001",
          service: "web",
          version: "prod",
        },
      ],
      http_method: "POST",
      relative_uri: "/ping",
    },
  ],
  attempt_deadline: "320s",
  description: "test app engine job",
  name: "test-job",
  retry_config: [
    {
      max_doublings: 2,
      max_retry_duration: "10s",
      min_backoff_duration: "1s",
      retry_count: 3,
    },
  ],
  schedule: "*/4 * * * *",
  time_zone: "Europe/London",
});

Example Usage - Scheduler Job Oauth

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const dataGoogleComputeDefaultServiceAccountDefault =
  new google.dataGoogleComputeDefaultServiceAccount.DataGoogleComputeDefaultServiceAccount(
    this,
    "default",
    {}
  );
new google.cloudSchedulerJob.CloudSchedulerJob(this, "job", {
  attempt_deadline: "320s",
  description: "test http job",
  http_target: [
    {
      http_method: "GET",
      oauth_token: [
        {
          service_account_email:
            dataGoogleComputeDefaultServiceAccountDefault.email,
        },
      ],
      uri: "https://cloudscheduler.googleapis.com/v1/projects/my-project-name/locations/us-west1/jobs",
    },
  ],
  name: "test-job",
  schedule: "*/8 * * * *",
  time_zone: "America/New_York",
});

Example Usage - Scheduler Job Oidc

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const dataGoogleComputeDefaultServiceAccountDefault =
  new google.dataGoogleComputeDefaultServiceAccount.DataGoogleComputeDefaultServiceAccount(
    this,
    "default",
    {}
  );
new google.cloudSchedulerJob.CloudSchedulerJob(this, "job", {
  attempt_deadline: "320s",
  description: "test http job",
  http_target: [
    {
      http_method: "GET",
      oidc_token: [
        {
          service_account_email:
            dataGoogleComputeDefaultServiceAccountDefault.email,
        },
      ],
      uri: "https://example.com/ping",
    },
  ],
  name: "test-job",
  schedule: "*/8 * * * *",
  time_zone: "America/New_York",
});

Argument Reference

The following arguments are supported:

  • name - (Required) The name of the job.

  • description - (Optional) A human-readable description for the job. This string must not contain more than 500 characters.

  • schedule - (Optional) Describes the schedule on which the job will be executed.

  • timeZone - (Optional) Specifies the time zone to be used in interpreting schedule. The value of this field must be a time zone name from the tz database.

  • paused - (Optional) Sets the job to a paused state. Jobs default to being enabled when this property is not set.

  • attemptDeadline - (Optional) The deadline for job attempts. If the request handler does not respond by this deadline then the request is cancelled and the attempt is marked as a DEADLINE_EXCEEDED failure. The failed attempt can be viewed in execution logs. Cloud Scheduler will retry the job according to the RetryConfig. The allowed duration for this deadline is:

    • For HTTP targets, between 15 seconds and 30 minutes.
    • For App Engine HTTP targets, between 15 seconds and 24 hours.
    • Note: For PubSub targets, this field is ignored - setting it will introduce an unresolvable diff. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s"
  • retryConfig - (Optional) By default, if a job does not complete successfully, meaning that an acknowledgement is not received from the handler, then it will be retried with exponential backoff according to the settings Structure is documented below.

  • pubsubTarget - (Optional) Pub/Sub target If the job providers a Pub/Sub target the cron will publish a message to the provided topic Structure is documented below.

  • appEngineHttpTarget - (Optional) App Engine HTTP target. If the job providers a App Engine HTTP target the cron will send a request to the service instance Structure is documented below.

  • httpTarget - (Optional) HTTP target. If the job providers a http_target the cron will send a request to the targeted url Structure is documented below.

  • region - (Optional) Region where the scheduler job resides. If it is not provided, Terraform will use the provider default.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The retryConfig block supports:

  • retryCount - (Optional) The number of attempts that the system will make to run a job using the exponential backoff procedure described by maxDoublings. Values greater than 5 and negative values are not allowed.

  • maxRetryDuration - (Optional) The time limit for retrying a failed job, measured from time when an execution was first attempted. If specified with retryCount, the job will be retried until both limits are reached. A duration in seconds with up to nine fractional digits, terminated by 's'.

  • minBackoffDuration - (Optional) The minimum amount of time to wait before retrying a job after it fails. A duration in seconds with up to nine fractional digits, terminated by 's'.

  • maxBackoffDuration - (Optional) The maximum amount of time to wait before retrying a job after it fails. A duration in seconds with up to nine fractional digits, terminated by 's'.

  • maxDoublings - (Optional) The time between retries will double maxDoublings times. A job's retry interval starts at minBackoffDuration, then doubles maxDoublings times, then increases linearly, and finally retries retries at intervals of maxBackoffDuration up to retryCount times.

The pubsubTarget block supports:

  • topicName - (Required) The full resource name for the Cloud Pub/Sub topic to which messages will be published when a job is delivered. ~>NOTE: The topic name must be in the same format as required by PubSub's PublishRequest.name, e.g. projects/myProject/topics/myTopic.

  • data - (Optional) The message payload for PubsubMessage. Pubsub message must contain either non-empty data, or at least one attribute. A base64-encoded string.

  • attributes - (Optional) Attributes for PubsubMessage. Pubsub message must contain either non-empty data, or at least one attribute.

The appEngineHttpTarget block supports:

  • httpMethod - (Optional) Which HTTP method to use for the request.

  • appEngineRouting - (Optional) App Engine Routing setting for the job. Structure is documented below.

  • relativeUri - (Required) The relative URI. The relative URL must begin with "/" and must be a valid HTTP relative URL. It can contain a path, query string arguments, and # fragments. If the relative URL is empty, then the root path "/" will be used. No spaces are allowed, and the maximum length allowed is 2083 characters

  • body - (Optional) HTTP request body. A request body is allowed only if the HTTP method is POST or PUT. It will result in invalid argument error to set a body on a job with an incompatible HttpMethod. A base64-encoded string.

  • headers - (Optional) HTTP request headers. This map contains the header field names and values. Headers can be set when the job is created.

The appEngineRouting block supports:

  • service - (Optional) App service. By default, the job is sent to the service which is the default service when the job is attempted.

  • version - (Optional) App version. By default, the job is sent to the version which is the default version when the job is attempted.

  • instance - (Optional) App instance. By default, the job is sent to an instance which is available when the job is attempted.

The httpTarget block supports:

  • uri - (Required) The full URI path that the request will be sent to.

  • httpMethod - (Optional) Which HTTP method to use for the request.

  • body - (Optional) HTTP request body. A request body is allowed only if the HTTP method is POST, PUT, or PATCH. It is an error to set body on a job with an incompatible HttpMethod. A base64-encoded string.

  • headers - (Optional) This map contains the header field names and values. Repeated headers are not supported, but a header value can contain commas.

  • oauthToken - (Optional) Contains information needed for generating an OAuth token. This type of authorization should be used when sending requests to a GCP endpoint. Structure is documented below.

  • oidcToken - (Optional) Contains information needed for generating an OpenID Connect token. This type of authorization should be used when sending requests to third party endpoints or Cloud Run. Structure is documented below.

The oauthToken block supports:

  • serviceAccountEmail - (Required) Service account email to be used for generating OAuth token. The service account must be within the same project as the job.

  • scope - (Optional) OAuth scope to be used for generating OAuth access token. If not specified, "https://www.googleapis.com/auth/cloud-platform" will be used.

The oidcToken block supports:

  • serviceAccountEmail - (Required) Service account email to be used for generating OAuth token. The service account must be within the same project as the job.

  • audience - (Optional) Audience to be used when generating OIDC token. If not specified, the URI specified in target will be used.

Attributes Reference

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

  • id - an identifier for the resource with format projects/{{project}}/locations/{{region}}/jobs/{{name}}

  • state - State of the job.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

Job can be imported using any of these accepted formats:

$ 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.