Google Cloud Scheduler Module#
This module simplifies the creation and management of Cloud Scheduler jobs on Google Cloud Platform. Google Cloud Scheduler is a fully managed enterprise-grade cron job scheduler that allows you to schedule virtually any job, including batch, big data jobs, cloud infrastructure operations, and more.
Compatibility#
This module is compatible with Terraform version >= 1.0 and has been tested with the following provider versions:
- Google Provider:
>= 4.0, < 6.0
Security Considerations#
- The service account used for scheduler jobs should have the minimum permissions required to perform the intended actions.
- Consider using OIDC token authentication for secure communication with Cloud Functions and other HTTP endpoints.
- Review the permissions granted to the service account to ensure they follow the principle of least privilege.
Usage#
The module creates Google Cloud Scheduler jobs with support for various authentication methods (OIDC and OAuth tokens) and HTTP methods. It's designed to be flexible and easy to use, with reasonable defaults and clear documentation.
Key features:
- Create multiple scheduler jobs using a single module
- Support for HTTP targets with various authentication methods
- Configurable schedule expressions using standard cron format
- Time zone support for accurate scheduling across regions
Basic Example without authentication#
module "cloud_scheduler" {
source = "github.com/myops-co/gcp-terraform-modules//modules/terraform-google-cloud-scheduler?ref=vX.Y.Z"
project_id = "my-project-id"
region = "europe-west1"
cloud_scheduler_config = {
"daily-backup-job" = {
description = "Triggers daily backup process"
schedule = "09 11 * * *"
time_zone = "Europe/Brussels"
http_method = "GET"
uri = "https://httpbin.org/get"
}
}
}
Advanced Example with Authentication#
module "cloud_scheduler" {
source = "github.com/myops-co/gcp-terraform-modules//modules/terraform-google-cloud-scheduler?ref=vX.Y.Z"
project_id = var.project_id
region = "us-central1"
cloud_scheduler_config = {
"daily-backup-job" = {
description = "Triggers daily backup process"
schedule = "0 4 * * *"
time_zone = "America/Los_Angeles"
http_method = "POST"
service_account_email = "cloud-scheduler@my-gcp-project.iam.gserviceaccount.com"
uri = "https://us-central1-my-gcp-project.cloudfunctions.net/backup-function"
oidc_token_enable = true
},
"hourly-monitoring-job" = {
description = "Runs hourly monitoring checks"
schedule = "0 * * * *"
time_zone = "UTC"
http_method = "GET"
service_account_email = "cloud-scheduler@my-gcp-project.iam.gserviceaccount.com"
uri = "https://us-central1-my-gcp-project.cloudfunctions.net/monitoring-function"
oauth_token_enable = true
scope = "https://www.googleapis.com/auth/cloud-platform"
},
"weekly-report-job" = {
description = "Generates weekly summary reports"
schedule = "0 9 * * MON"
time_zone = "Europe/London"
http_method = "POST"
service_account_email = "cloud-scheduler@my-gcp-project.iam.gserviceaccount.com"
uri = "https://us-central1-my-gcp-project.cloudfunctions.net/reporting-function"
body = "{\"report_type\":\"weekly\",\"format\":\"pdf\"}"
oidc_token_enable = true
audience = "https://us-central1-my-gcp-project.cloudfunctions.net"
}
}
}
Software#
This module requires the following software dependencies:
- Terraform
>= 1.0 - Google Cloud Provider
>= 4.0, < 6.0
Service Account#
The service account used to run this module must have the following IAM roles:
roles/cloudscheduler.admin- To create and manage Cloud Scheduler jobsroles/iam.serviceAccountUser- To impersonate service accounts for job execution (if using service account authentication)
APIs#
The following GCP APIs must be enabled in the target project:
- Cloud Scheduler API (
cloudscheduler.googleapis.com) - Cloud Resource Manager API (
cloudresourcemanager.googleapis.com)
License#
This module is covered by a commercial license. Please see LICENSE for details.
Support#
This module is developed and maintained by MyOps Limited. For any support inquiries, please contact us at info@myops.co.il.
Requirements#
| Name | Version |
|---|---|
| terraform | >= 1.0 |
| >= 4.0, < 6.0 |
Providers#
| Name | Version |
|---|---|
| >= 4.0, < 6.0 |
Modules#
No modules.
Resources#
| Name | Type |
|---|---|
| google_cloud_scheduler_job.scheduler_job | resource |
Inputs#
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| cloud_scheduler_config | Map of configurations for Cloud Scheduler jobs. The map key is used as the job name. | map(object({ |
n/a | yes |
| project_id | (Required) The ID of the project where the cloud scheduler will be created. | string |
n/a | yes |
| region | Region where the scheduler job resides. | string |
n/a | yes |
Outputs#
| Name | Description |
|---|---|
| scheduler_job_ids | Map of Cloud Scheduler job IDs in format: projects/{{project}}/locations/{{region}}/jobs/{{name}} |
| scheduler_job_names | Names of the created scheduler jobs |
| scheduler_job_states | States of the created scheduler jobs |