chainguard-dev / terraform-google-cron

Terraform module for deploying cron jobs that run on a defined schedule

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cloud Run-based cron jobs.

This repository contains a terraform module for deploying cron jobs that run on a defined schedule.

Defining a custom cron job.

A cron job can be defined as a simple Go program, with as little code as:

import "log"

func main() {
    log.Println("hello")
}

See our example.

Deploying a custom cron job

With the terraform module provided here, a cron job can be deployed with a little configuration as:

module "cron" {
  source  = "chainguard-dev/cron/google"
  version = "v0.1.2"

  name       = "example"
  project_id = var.project_id
  schedule   = "*/8 * * * *"  # Every 8 minutes.

  importpath  = "github.com/chainguard-dev/terraform-google-cron/example"
  working_dir = path.module
}

See our example.

Passing additional configuration

You can pass additional configuration to your custom cron jobs via environment variables passed to the application. These can be specified in the module:

  env = {
    "FOO" : "bar"
  }

See our example.

or as from a secret in Google Secret Manager:

  env_secret = {
    "FOO" : "secret_name_in_secret_manager"
  }

Requirements

No requirements.

Providers

Name Version
google n/a
ko n/a

Modules

No modules.

Resources

Name Type
google_cloud_run_v2_job.job resource
google_cloud_run_v2_job_iam_binding.authorize-calls resource
google_cloud_scheduler_job.cron resource
google_project_service.cloud_run_api resource
google_project_service.cloudscheduler resource
google_service_account.delivery resource
ko_build.image resource

Inputs

Name Description Type Default Required
base_image The base image that will be used to build the container image. string "cgr.dev/chainguard/static:latest-glibc" no
cpu The CPU limit for the job. string "1000m" no
env A map of custom environment variables (e.g. key=value) map {} no
execution_environment The execution environment to use for the job. string "" no
importpath The import path that contains the cron application. string n/a yes
max_retries The maximum number of times to retry the job. number 3 no
memory The memory limit for the job. string "512Mi" no
name Name to prefix to created resources. any n/a yes
project_id The project that will host the cron job. string n/a yes
region The region to run the job. string "us-east4" no
repository Container repository to publish images to. string "" no
schedule The cron schedule on which to run the job. any n/a yes
secret_env A map of secrets to mount as environment variables from Google Secrets Manager (e.g. secret_key=secret_name) map {} no
service_account The email address of the service account to run the service as, and to invoke the job as. string n/a yes
timeout The maximum amount of time in seconds to allow the job to run. string "600s" no
vpc_access The VPC to send egress to. For more information, visit https://cloud.google.com/run/docs/configuring/vpc-direct-vpc
object({
# Currently, only one network interface is supported.
network_interfaces = list(object({
network = string
subnetwork = string
tags = optional(list(string))
}))
# Egress is one of "PRIVATE_RANGES_ONLY", "ALL_TRAFFIC", or "ALL_PRIVATE_RANGES"
egress = string
})
null no
working_dir The working directory that contains the importpath. string n/a yes

Outputs

No outputs.

About

Terraform module for deploying cron jobs that run on a defined schedule

License:Apache License 2.0


Languages

Language:HCL 97.9%Language:Go 2.1%