Google Cloud Scheduler Job
This page shows how to write Terraform for Cloud Scheduler Job and write them securely.
google_cloud_scheduler_job (Terraform)
The Job in Cloud Scheduler can be configured in Terraform with the resource name google_cloud_scheduler_job
. The following sections describe 2 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "google_cloud_scheduler_job" "ali" {
name = "Search_BOT_ALI_EXPRESS"
description = "Search BOT ALI EXPRESS"
schedule = var.cron_pattern_ali
region = var.function_location
time_zone = "Europe/Amsterdam"
resource "google_cloud_scheduler_job" "daily_amplitude_job" {
name = "amplitude_import_daily_run"
description = "Runs once a day at 3am. It sends a message to Pub/Sub which then triggers the function that syncs data from Amplitude to BigQuery"
schedule = "0 3 * * *"
pubsub_target {
Parameters
-
attempt_deadline
optional - string
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 DEADLINEEXCEEDED 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"
-
description
optional - string
A human-readable description for the job. This string must not contain more than 500 characters.
The name of the job.
Region where the scheduler job resides. If it is not provided, Terraform will use the provider default.
-
schedule
optional - string
Describes the schedule on which the job will be executed.
-
time_zone
optional - string
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.
-
app_engine_http_target
list block-
body
optional - string
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 - map from string to string
HTTP request headers. This map contains the header field names and values. Headers can be set when the job is created.
-
http_method
optional - string
Which HTTP method to use for the request.
-
relative_uri
required - string
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
-
app_engine_routing
list block-
instance
optional - string
App instance. By default, the job is sent to an instance which is available when the job is attempted.
-
service
optional - string
App service. By default, the job is sent to the service which is the default service when the job is attempted.
-
version
optional - string
App version. By default, the job is sent to the version which is the default version when the job is attempted.
-
-
-
http_target
list block-
body
optional - string
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 - map from string to string
This map contains the header field names and values. Repeated headers are not supported, but a header value can contain commas.
-
http_method
optional - string
Which HTTP method to use for the request.
-
uri
required - string
The full URI path that the request will be sent to.
-
oauth_token
list block-
scope
optional - string
OAuth scope to be used for generating OAuth access token. If not specified, "https://www.googleapis.com/auth/cloud-platform" will be used.
-
service_account_email
required - string
Service account email to be used for generating OAuth token. The service account must be within the same project as the job.
-
-
oidc_token
list block-
audience
optional - string
Audience to be used when generating OIDC token. If not specified, the URI specified in target will be used.
-
service_account_email
required - string
Service account email to be used for generating OAuth token. The service account must be within the same project as the job.
-
-
-
pubsub_target
list block-
attributes
optional - map from string to string
Attributes for PubsubMessage. Pubsub message must contain either non-empty data, or at least one attribute.
-
data
optional - string
The message payload for PubsubMessage. Pubsub message must contain either non-empty data, or at least one attribute. A base64-encoded string.
-
topic_name
required - string
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/my-project/topics/my-topic'.
-
-
retry_config
list block-
max_backoff_duration
optional computed - string
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'.
-
max_doublings
optional computed - number
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.
-
max_retry_duration
optional computed - string
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'.
-
min_backoff_duration
optional computed - string
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'.
-
retry_count
optional computed - number
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.
-
-
timeouts
single block
Explanation in Terraform Registry
A scheduled job that can publish a pubsub message or a http request every X interval of time, using crontab format string. To use Cloud Scheduler your project must contain an App Engine app that is located in one of the supported regions. If your project does not have an App Engine app, you must create one. To get more information about Job, see:
- API documentation
- How-to Guides
Frequently asked questions
What is Google Cloud Scheduler Job?
Google Cloud Scheduler Job is a resource for Cloud Scheduler of Google Cloud Platform. Settings can be wrote in Terraform.
Where can I find the example code for the Google Cloud Scheduler Job?
For Terraform, the greenpeace/gp-intellectual-property-rights-tracking and luke-jordan/jupiter-data source code examples are useful. See the Terraform Example section for further details.