Files
solution_architecture_agent/skills/google-cloud-iac-patterns/references/cloud-run-job.md
Jonathan Boniface c84dbdea20 feat: the solution architecture agent on the shared Execution engine
The reference agent's subject, cloud solution architecture, as an agent in
the operating model agent's pattern: the Execution engine (from
orchestration_engine) and one Workflow in app/solution_architecture,
built for the settings and provider bundle by assembly.workflow_for.

Copied from gcp_solution_architecture_agent at 8b397cd without its own
engine: its role files, Skills, provider bundle, ADRs, vocabulary, scripts
and evaluation datasets. The image takes the engine from a named build
context and installs Terraform. It is called through the Orchestration
engine, and its files are what the operating model agent digests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 19:49:28 +01:00

2.7 KiB

Cloud Run job

google_cloud_run_v2_job: a task that runs to completion. It is a different resource type from a service, and its template is nested one level deeper.

What a job does not have. A Check that asks for one of these on a job cannot be met:

  • startup_cpu_boost and cpu_idle. A job's resources block has limits only.
  • ingress, traffic, scaling, min_instance_count, max_instance_request_concurrency. A job answers no requests.
  • liveness_probe. A job's container has a startup_probe only.

Where a job's settings sit:

  • task_count and parallelism are in template.
  • service_account, timeout, max_retries, execution_environment, vpc_access and encryption_key are in template.template.
  • image, env, args, command and resources are in template.template.containers.
  • Whoever starts the job needs roles/run.invoker on it; Cloud Scheduler starts it with an HTTP call to the :run method.
variable "project_id" {
  type        = string
  description = "Project to deploy into."
}

variable "region" {
  type        = string
  description = "Region for regional resources."
}

variable "image" {
  type        = string
  description = "Container image reference, including the tag or digest."
}

variable "deletion_protection" {
  type        = bool
  description = "Whether Terraform is prevented from deleting the job."
  default     = true
}

resource "google_service_account" "replay" {
  project      = var.project_id
  account_id   = "replay-job"
  display_name = "Replay job"
}

resource "google_cloud_run_v2_job" "replay" {
  project             = var.project_id
  name                = "replay"
  location            = var.region
  deletion_protection = var.deletion_protection

  template {
    task_count  = 1
    parallelism = 1

    template {
      service_account       = google_service_account.replay.email
      timeout               = "3600s"
      max_retries           = 3
      execution_environment = "EXECUTION_ENVIRONMENT_GEN2"

      containers {
        image = var.image
        args  = ["--mode=replay"]

        resources {
          limits = {
            cpu    = "1"
            memory = "1Gi"
          }
        }

        env {
          name  = "BATCH_SIZE"
          value = "100"
        }
      }
    }
  }
}

resource "google_service_account" "operator" {
  project      = var.project_id
  account_id   = "replay-operator"
  display_name = "Starts the replay job"
}

resource "google_cloud_run_v2_job_iam_member" "operator_runs_replay" {
  project  = var.project_id
  location = google_cloud_run_v2_job.replay.location
  name     = google_cloud_run_v2_job.replay.name
  role     = "roles/run.invoker"
  member   = google_service_account.operator.member
}