blob: 1f417a763c7d83baaabc18804071dd7b3e004f5a [file] [log] [blame]
---
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in
# .github/CONTRIBUTING.md.
#
# ----------------------------------------------------------------------------
subcategory: "Cloud Scheduler"
description: |-
A scheduled job that can publish a PubSub message or an HTTP request
every X interval of time, using a crontab format string.
---
# 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:
* [API documentation](https://cloud.google.com/scheduler/docs/reference/rest/)
* How-to Guides
* [Official Documentation](https://cloud.google.com/scheduler/)
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=scheduler_job_pubsub&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Scheduler Job Pubsub
```hcl
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")
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=scheduler_job_http&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Scheduler Job Http
```hcl
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"
}
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=scheduler_job_paused&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Scheduler Job Paused
```hcl
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"
}
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=scheduler_job_app_engine&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Scheduler Job App Engine
```hcl
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
```hcl
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
}
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=scheduler_job_oidc&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Scheduler Job Oidc
```hcl
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:
* `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.
* `time_zone` -
(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.
* `attempt_deadline` -
(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"
* `retry_config` -
(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](#nested_retry_config).
* `pubsub_target` -
(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](#nested_pubsub_target).
* `app_engine_http_target` -
(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](#nested_app_engine_http_target).
* `http_target` -
(Optional)
HTTP target.
If the job providers a http_target the cron will
send a request to the targeted url
Structure is [documented below](#nested_http_target).
* `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.
<a name="nested_retry_config"></a>The `retry_config` block supports:
* `retry_count` -
(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.
* `max_retry_duration` -
(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'.
* `min_backoff_duration` -
(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'.
* `max_backoff_duration` -
(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'.
* `max_doublings` -
(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.
<a name="nested_pubsub_target"></a>The `pubsub_target` block supports:
* `topic_name` -
(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/my-project/topics/my-topic`.
* `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.
<a name="nested_app_engine_http_target"></a>The `app_engine_http_target` block supports:
* `http_method` -
(Optional)
Which HTTP method to use for the request.
* `app_engine_routing` -
(Optional)
App Engine Routing setting for the job.
Structure is [documented below](#nested_app_engine_routing).
* `relative_uri` -
(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.
<a name="nested_app_engine_routing"></a>The `app_engine_routing` 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.
<a name="nested_http_target"></a>The `http_target` block supports:
* `uri` -
(Required)
The full URI path that the request will be sent to.
* `http_method` -
(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.
* `oauth_token` -
(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](#nested_oauth_token).
* `oidc_token` -
(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](#nested_oidc_token).
<a name="nested_oauth_token"></a>The `oauth_token` block supports:
* `service_account_email` -
(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.
<a name="nested_oidc_token"></a>The `oidc_token` block supports:
* `service_account_email` -
(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](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-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:
* `projects/{{project}}/locations/{{region}}/jobs/{{name}}`
* `{{project}}/{{region}}/{{name}}`
* `{{region}}/{{name}}`
* `{{name}}`
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Job using one of the formats above. For example:
```tf
import {
id = "projects/{{project}}/locations/{{region}}/jobs/{{name}}"
to = google_cloud_scheduler_job.default
}
```
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), 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](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).