Back to Terraform

Cloud Run and Event Delivery: Artifacts, Service Identities and Triggers

November 6, 2026 Wasil Zafar 32 min read

Promote serverless application versions and connect events without broadening invocation or data access

Table of Contents

  1. Build the Image or Source Artifact Before Planning
  2. Map Deployer, Runtime and Invocation Identities
  3. Connect Pub/Sub, Eventarc or Scheduled Work Deliberately
  4. Handle Revision Traffic and Application Configuration Ownership
  5. Test Allowed, Denied and Retried Events

Build the Image or Source Artifact Before Planning

The artifact is the input Terraform cannot invent. A Cloud Run service accepts a container image reference, and a Cloud Run function accepts a source object that the platform builds into one. Everything else in the resource describes how that artifact runs, so the bytes must exist and be identified before the plan is written.

Three artifact models cover most pipelines, and they leave Terraform different amounts to see. The table is not a preference order; it maps what the pipeline hands over to what the resource can record.

Artifact modelWhat the pipeline hands overWhat builds itWhat Terraform recordsFailure when the reference is mutable
Container image, digestimage reference with a digestCI builder, outside the applyimage string containing the digestnone, the digest pins the bytes
Container image, tagimage reference with a tagCI builder, outside the applyimage string containing the tagtag moves, plan stays empty, revision unchanged
Cloud Run source deploysource archiveCloud Build and buildpacksnot a Terraform field at allbuild identity and repository never reviewed
Function sourceobject name and generationCloud Buildbucket, object, generationgeneration omitted, latest object rebuilt silently

A tag is a pointer; a digest is a record. Terraform compares the string in the configuration with the string in state, not the bytes in the registry. Re-pushing a tag leaves the plan empty and the running revision untouched, which is why a reviewed service image belongs in the configuration as a digest.

Cloud Run functions changed name, not shape. The product is now presented as Cloud Run functions, and a function is a Cloud Run service deployed from source. In provider 8.10.0 the resource is still google_cloudfunctions2_function, with separate build, service and trigger blocks.

The function resource owns two artifacts at once. build_config selects the runtime, entry point and source generation, while service_config describes the Cloud Run service that will run the built image. The build identity and the runtime identity are different principals, which the next section tests.

Every template edit creates a revision. Image, environment variables, service account, timeout and scaling all live in the revision template, so each edit produces a new revision rather than mutating the old one. Old revisions remain addressable, which is what makes a rollback a routing change instead of a rebuild.

The release record has five fields. Digest, runtime, revision name, build id and runtime identity are enough to answer what ran, as whom and from which bytes. If one is missing, the next incident starts by reconstructing history rather than reading it.

A source deploy is still a build, just not yours. Cloud Run can turn a source archive into an image with buildpacks, and what you get is the same service resource with an image field. The recipe, the base image and the build identity stay in the pipeline, so Terraform sees the result and never the build.

The build identity is a separate grant from the runtime identity. For a function, the build account reads the source object, writes the image and emits build logs, while the runtime account pulls the image and runs it. The provider's own example grants image read access to the runtime account, which is a reminder that build and run permissions are two lists with two holders.

Build the Image or Source Artifact Before Planning
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    S["Commit and pinned build image"] --> B["Build outside Terraform"]
    B --> D["Image digest and build id"]
    D --> A["Artifact Registry
immutable digest"] A --> T["Terraform service or function
image by digest"] T --> R["Revision
image, env, identity"] R --> P["Traffic split
latest, percent, tag"] P --> V["Version route
answers with the digest"] B -.->|"tag re-pushed"| X1["Plan is empty
old revision still serves"] A -.->|"source object overwritten"| X2["Latest generation built
without a review"] T -.->|"source built during apply"| X3["Applied image differs
from the reviewed one"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class S,B primary; class D,A secondary; class T,R,P,V ok; class X1,X2,X3 danger;
The artifact is built and stored outside Terraform, the service records the digest, and the revision and traffic split are separate objects A source commit is built into an image whose digest is stored in Artifact Registry. Terraform records that digest in a service, job or function contract with a runtime and identity. Each template change creates an immutable revision, and a mutable traffic block decides which revision receives requests. A footer warns that a re-pushed tag changes the registry but not the plan. An artifact, a contract, a revision and a split Only the middle layer is Terraform, and only the split is safe to move by hand. Outside Terraform Source and lockfile commit, dependencies, build image Build Cloud Build or buildpacks Artifact Registry image digest and build id the identity of the bytes Terraform contract Service, job or function image or source reference runtime and identity timeout and environment Invoker and runtime grants not part of the revision A template edit creates a revision. A traffic edit does not. digest Created by the API Revision immutable after creation image, env, identity named or generated Traffic split latest or revision percent and tag mutable pointer A re-pushed tag changes the registry, not the plan. Resolve the digest in the pipeline and compare it with the approved release record before applying.

The artifact boundary is the review boundary. A reviewer who can see the digest, the runtime and the revision name has reviewed the deployment. A reviewer who sees only a tag has reviewed a name that may point at different bytes by the time the apply runs.

Map Deployer, Runtime and Invocation Identities

Four identities appear in one deployment, and only one of them runs your code. The deployer writes the resources, the build identity compiles a function, the runtime identity executes the revision, and the invocation identity calls it. Each has a different scope, so merging any two widens the blast radius of both.

The schema names each identity in a different place. That separation is deliberate, and a review that checks only the service account field has checked the runtime identity and nothing else.

IdentityDeclared inNeedsIf it is shared
Deployerpipeline principal or Terraformrun admin, trigger admin, act ascan deploy or retarget anything in the project
Buildbuild account on the functionimage write, source read, log writeone build can publish images for other services
Runtimerevision template or service configonly the data roles the code usescode can read every dataset that identity reaches
Invocationpush token, trigger account or scheduler accountinvoker on the service or jobany caller can reach any service it is bound to

Omitting the runtime identity is still a choice. A service without an explicit service account runs as the project's default compute identity, which often carries broad roles granted for an earlier workload. Set the identity on every service and job, even when the code currently needs nothing.

Acting as an identity is a separate permission. The deployer needs roles/iam.serviceAccountUser on the runtime identity and on the trigger identity, because the revision and the trigger both run as them. A deploy that fails on permission to act as a service account is not a Cloud Run permission problem.

The runtime identity is not an invoker. It authorizes calls the code makes to Google APIs, not calls made to the service. If the code calls its own service or another private service, that path needs an invocation identity and a token whose audience is the target URL.

Three grants make one trigger work, and each has a different holder.

GrantHolderGranted onSymptom when absent
token creatorplatform service agentinvocation service accountdelivery fails before a request is made
invokerinvocation service accountCloud Run service or job403 at the platform edge
event receivertrigger service accountprojecttrigger cannot receive from the provider
publisherstorage service agentEventarc transport topicdirect storage events never arrive

The platform agent grant is often already present. Projects whose Pub/Sub service agent was enabled after 8 April 2021 receive the token creator binding by default. Verify the effective policy before adding a duplicate, and do not remove the binding to tidy up: delivery fails before a request is made.

The trigger identity is not a data identity. Eventarc, Pub/Sub and Scheduler all call the service; none of them read your bucket or database. Granting storage access to the trigger account because the event originated in storage is the most common over-grant in this design.

Terraform cannot infer a dependency in another control plane. An IAM binding and a trigger are different APIs, so the graph may create the trigger before the grant is effective. Add the dependency explicitly, and still allow minutes for propagation in the test.

Prefer a user-managed identity that you create first. It can exist before the service, it survives a service replacement, and its grants are reviewable on their own. A Google-managed default identity cannot be granted to before the resource exists, which pushes part of the contract into a second apply.

The build identity is the easiest one to leave implicit. When a function omits its build account, the build runs as a project default that may be broader than any human deployer. Set it explicitly, and grant only the repository, bucket and log destination the build actually uses.

Workload Identity Federation is not the mechanism here. Cloud Run and Cloud Run functions receive their identity from the platform, so a revision needs no key file and no federation pool. Federation belongs to the pipeline that deploys, not to the workload that runs.

An invocation grant can be scoped to one service. Prefer a service-level binding over a project-level one, because a project invoker grant reaches every service that identity can see. The same logic applies to a job: bind on the job, not on the project.

Two identity chains: a platform agent mints a token for the invocation identity, while the deployer acts as the runtime identity The delivery chain runs from an event source through a platform agent and an invocation identity to the Cloud Run edge. The runtime chain runs from the deployer, which acts as the runtime service account, to the revision and then to data APIs. A failure strip shows where each refusal stops: ingress, a 401 for a missing token, a 403 for a missing invoker grant, and a later 403 from a dependency when the runtime identity lacks a data role. Two chains, four identities The caller is allowed in; the revision is allowed out. DELIVERY PATH Event source Pub/Sub, Storage, or a schedule the fact to deliver Platform agent mints the token acts for the caller needs token creator Invocation SA run.invoker on this service or this job Cloud Run edge ingress first then the IAM check both must pass event token ID token RUNTIME PATH Deployer pipeline principal writes the contract not the data path Runtime SA revision identity data roles only no invoker by default Revision runs as that identity image is already fixed env is already fixed Data APIs checked per call Storage, Pub/Sub, Secret Manager acts as template token Where a refusal stops No route ingress refused it 401 no valid token 403 no invoker grant 403 later runtime SA lacks a data role The trigger identity invokes; the runtime identity reads. Sharing them grants both.

Read the policy, not the plan. After apply, confirm the binding names the service account the service actually reports and the scope you intended. A grant to a stale principal looks correct in state and authorizes nobody.

Map Deployer, Runtime and Invocation Identities
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    P["Event source or schedule"] --> A["Platform agent mints
a token for the caller"] A --> I{"Ingress admits
the request?"} I -->|"no"| E1["Refused before routing
no revision log"] I -->|"yes"| H{"Caller holds
run.invoker?"} H -->|"no"| E2["403 at the platform edge
no revision log"] H -->|"yes"| C["Revision starts
as the runtime SA"] C --> D{"Runtime SA holds
the data role?"} D -->|"no"| E3["Dependency returns 403
after the invocation"] D -->|"yes"| OK["Work completes
and acknowledges"] OK --> K["Idempotency key stored
with the write"] A -.->|"no token creator grant"| F1["Agent cannot sign
delivery never starts"] C -.->|"identity left unset"| F2["Revision runs as
the default SA"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class P primary; class A,C secondary; class I,H,D warn; class OK,K ok; class E1,E2,E3,F1,F2 danger;

A failure names the gate that refused it. A refused connection points at ingress, a 401 at the token, a 403 at the invoker grant, and a 403 from a dependency at the runtime identity. The status code plus the presence or absence of a revision log separates the four faster than reading the policy.

Connect Pub/Sub, Eventarc or Scheduled Work Deliberately

The trigger choice is a choice about who owns the retry. A Pub/Sub push subscription retries an unacknowledged message, Eventarc retries through its transport subscription, and Scheduler retries the HTTP call. Naming the owner first predicts the failure you will debug.

Service, job and function are three different contracts. They share a container format and an identity model, and they disagree about what a request means.

Work shapeResourceRetry ownerCaller identityFits when
request or event receiverCloud Run servicecaller or triggerinvoker accountan HTTP API or an event consumer needs a URL
run to completionCloud Run jobtask retries per executioninvoker accountbatch, migration or a long task with no request
source plus triggerCloud Run functionEventarc triggertrigger accounta small handler whose build can live with the resource
time-based callCloud Scheduler jobscheduler retry configOIDC or OAuth accountcron for a service route or a job execution

A job is not a service with fewer features. It has executions, tasks, parallelism and a task timeout, but no URL, no revision traffic and no HTTP request. Eventarc's destination block addresses Cloud Run services, so an event cannot start a job without a service in front of it.

Pub/Sub push turns the acknowledgement deadline into a request timeout. The subscription applies its ack deadline, between 10 and 600 seconds, to the push call. A Cloud Run timeout longer than that deadline lets the platform cut the request and redeliver while the first attempt is still running.

Push delivery is at least once, so the handler owns the key. The same message id can arrive twice after a negative acknowledgement, an expired deadline or a transport retry. Store an idempotency key with the write rather than hoping the second delivery finds the first result.

Dead-lettering is a second resource and a second grant. A dead-letter topic needs the Pub/Sub service agent's publish and acknowledge permissions, and the subscription's attempt ceiling sits between 5 and 100. Without the grant, messages keep retrying and nothing is captured.

Eventarc is a filter in front of a Pub/Sub transport. Set the trigger location to the event source's location, and set the destination region explicitly rather than relying on the default. A Cloud Storage source bucket must be in the same project and the same region or multi-region as the trigger, and a message storage policy that excludes the source region can still break it.

A storage trigger needs the storage agent's publish grant. Direct Cloud Storage events travel through a transport topic that the storage service agent must be allowed to publish to. The grant is easy to miss because the trigger is created successfully and simply never fires.

Eventarc retry has two modes, not a full policy. Leaving the retry block unset keeps the transport's default exponential retry window. Setting a single attempt is the no-retry mode the provider exposes, and it is the right choice for a handler that cannot be idempotent.

Audit-log triggers are a different bill. An audit-log trigger only sees events when data-access audit logs are enabled for the service, and those logs are billed. Filter on the service and method you need, or the trigger becomes a subscription to everything.

Scheduler calls two different APIs with two token types. A run.app service takes an OIDC token whose audience is the service URL. The Cloud Run jobs API lives on googleapis.com, so the same schedule needs an OAuth token instead.

The audience must not carry query parameters. Scheduler can pass a query string, but the audience claim must identify the service alone. A token minted for the full URL including parameters is rejected even though the request looks right.

A trigger has a state you can read. Eventarc reports conditions with a reason, and a trigger stuck in a failed state is better evidence than an event that never arrived. Check the trigger before you check the code.

Ordering is a subscription property, not a trigger property. Pub/Sub delivers in order only when the publisher sets an ordering key and the subscription enables ordering, and Eventarc offers no such guarantee. A handler that assumes arrival order passes a single-message test and fails under load.

A trigger update does not rewrite events already in flight. For a bounded window after a filter or destination change, an event generated before the update can still follow the previous route. Publish a fresh event to test the new route, and do not read old deliveries as evidence about the new trigger.

Scheduler's attempt deadline is shorter than a long job. Scheduler gives up at the configured attempt deadline and records a failure even if the target is still working. Work that can outlive a synchronous call belongs behind the jobs API with its own task timeout, not behind an HTTP request that Scheduler will abandon.

TriggerDeliveryOrderingPoison pathVerify with
Pub/Sub pushat least onceonly with an ordering keydead-letter topicack and delivery count
Eventarc triggerat least oncenonetransport retention or dead-letter policytrigger conditions and event id
Schedulerper attemptnoneretry configuration exhaustedexecution log and status
Direct HTTPsynchronousper requestreturned to the callerstatus code and revision log

The cheapest trigger is the one you can explain in one sentence. "A bucket event starts this handler" and "a schedule calls this job" predict different identities, retries and failure evidence. If the sentence needs three clauses, the trigger is doing more than one job.

Handle Revision Traffic and Application Configuration Ownership

A revision is a fact; traffic is a pointer. The revision holds the image, environment, identity and timeout, and it never changes after creation. The traffic block is mutable and says which revisions receive requests, so changing traffic alone does not create a revision.

A tag is a URL for one revision. Tagged traffic gives a stable address even when the revision receives no percentage, which makes a canary a two-step operation: call the tag URL, then move the split. The token audience stays the service URL, not the tag URL.

Naming a revision makes a split expressible in one apply. The generated name is unknown until the revision exists, so the same resource cannot reference it in its traffic block. Setting an explicit revision name fixes that, at the cost of changing the name with every template edit, because a revision name cannot be reused for different content.

Cloud Run functions hide a traffic switch. The function's latest-revision flag defaults to true, so every deploy takes all traffic. Setting it false only helps after the underlying service is pinned to a revision name; otherwise the new deployment becomes latest and intercepts the traffic anyway.

Two release tools produce drift, not redundancy. Terraform owning traffic while a pipeline deploys produces a split that resets at the next apply. A pipeline owning traffic while Terraform owns the template produces a revision that reappears at every deploy.

Environment variables are revision content. A configuration tool that edits an environment variable creates a new revision with the same image, and Terraform will revert it if the template is in state. Keep stable keys in the template and move values to Secret Manager references, or give the whole template to one owner.

Ignore rules must be narrow. Ignoring the traffic block hands routing to the release tool; ignoring the whole template also hides image and identity changes. Write the ownership down, because the ignore list is what the next engineer will read instead.

A rollback is a traffic change. Point the split at the previous revision and keep the digest in the release record. Rebuilding the previous commit during an incident tests the build system at the worst possible moment.

A split is not a deployment gate. Moving percentage changes where requests go; it does not prove the new revision works. Send real requests to the tag URL and read the version route before moving traffic, or the split becomes an uncontrolled experiment on users.

A tag is independent of the percentage. A candidate can be reachable at zero percent while the previous release keeps its own address, which is what allows a rollback and a canary to coexist. Delete each tag when its rollout ends, because a tag that outlives its revision is a URL that fails long after the release note.

FieldOne ownerConflict symptomRecovery
Image referencepipeline or Terraformplan reverts a deploychoose one and stop the other
Traffic splitrelease tool or Terraformsplit resets on every applynarrow ignore rule on traffic only
Environmenttemplate owner or config toolrevision churn with no image changestable keys plus secret references
Runtime identityTerraformrevision runs as the wrong accountexplicit service account on the template
Revision nameTerraformimmutable revision rejectedderive the name from the release id
Two writers on one traffic block produce drift, while one owner per field keeps the split and the template coherent The left panel shows Terraform applying a traffic split while a pipeline deploy moves the latest revision, so the last writer wins. The right panel assigns the artifact and revision template to the pipeline, the traffic split to the release tool, and environment values to secret references, with a narrow ignore rule on traffic. One field, one writer A traffic block with two authors is a race, not a rollout strategy. Before: two writers on one traffic block Terraform traffic percentage, template and identity applied on a merge Cloud Run service one traffic block, two authors Pipeline deploy latest revision becomes 100 percent apply deploy last writer wins, and the previous split is lost After: one owner per field Artifact and revision template pipeline records the digest and the revision name Traffic split release tool moves percent and tags Environment stable keys, secret references, no drift ignore change on traffic only, never on the whole template Two writers do not add redundancy; they add drift.

The ownership table is the review artefact. A short table naming the owner of the image, the template, the split and the environment prevents most of the arguments that follow a bad rollout. The ignore rules should match the table, not contradict it.

Test Allowed, Denied and Retried Events

A green apply proves none of the three paths. Ingress, authentication and authorization are separate gates, and a service can pass one while failing the next. Test each gate with the identity that will actually use it.

Ingress is admission, not permission. Internal ingress admits same-project Eventarc, Pub/Sub and Scheduler traffic over the Google network, and refuses a laptop and callers outside the project or its perimeter. It does not grant the caller permission, and it does not replace a token.

Authentication and authorization fail differently. A missing or invalid token returns 401; a valid identity without the invoker grant returns 403. Both are refused at the platform edge, so the revision log stays empty while the request log records the status.

A denied request is a passing test. Remove the invoker binding, call again and expect a refusal with no invocation. Restore the binding and allow propagation, because a grant created seconds ago can still return 403 for several minutes.

The retry test counts writes. A handler that writes and then fails will be called again, and the second call writes again unless the key already exists. Two deliveries with one record is the pass; two records is the bug the test was built to find.

A timeout mismatch is the quiet duplicate. When the delivery deadline is shorter than the handler, the platform retries while the first attempt still runs. Put the service timeout inside the delivery budget, or return early and continue the work elsewhere.

Payload shape is part of the contract. Pub/Sub push wraps the body in a message envelope and base64-encodes the data, Eventarc sends a CloudEvent with attributes, and a direct call sends your body. A hand-written object tests the parser you wrote, not the wiring you deployed.

Telemetry must be useful after redaction. Log the message id, event id and revision name, not the payload. That is enough to join a retry to its first attempt without copying customer data into logs.

Read the request log before the revision log. A refused request appears in the request log with a status and no revision line, while an accepted request appears in both. That single comparison separates admission, identity and code faster than any dashboard.

Test the tag URL as well as the service URL. A tag address serves one revision, and the token audience remains the service URL. If the tag request fails while the root request succeeds, the audience or the tag is wrong, not the handler.

A retry test needs a bounded wait. Poll the record count and the dead-letter topic for a fixed window instead of sleeping for the maximum retention. The test should fail on a timeout, not hang until the transport gives up.

Lab

Test Allowed, Denied and Retried Events

Status: design-only. No Google Cloud project or credential was used to produce this article, and these steps were not executed here. Versions: Terraform CLI 1.17.1, hashicorp/google 8.10.0, verified 6 November 2026.

Prerequisites. A sandbox project with billing enabled, one Artifact Registry repository holding the image digest under test, one Cloud Run service and one job, a Pub/Sub topic with a dead-letter topic, a Cloud Storage bucket in the service region, two service accounts, and permission to read request logs, revision logs and trigger conditions.

Setup. The service answers a version route with the digest it was deployed from and writes a record for each event it processes. The record key is the message id, so a duplicate delivery is visible as a count rather than an impression. Keep the handler short; the lab tests identity, admission and retry, not business logic.

ObjectLab valueWhy it matters
Servicepinned image digest, internal ingress, no public invokeringress and IAM are tested separately
Runtime identityexplicit service account, no project-wide rolesa dependency 403 is reproducible
Invocation identityinvoker on the service onlythe denied path is one binding away
Push subscriptionOIDC token, short ack deadline, dead-letter topicretry and poison are observable
Eventarc triggerstorage finalized event, same region as the bucketfilter and location must align
Scheduler jobOIDC to the service, OAuth to the jobs APItoken type depends on the target
  1. Apply the base. Create the service, the job, the identities and the bindings, then read back the service URL, the revision name and the identity the revision reports.
  2. Call without a token. Expect 401 and an empty revision log; the request log records the refusal. This is the authentication test, not the authorization test.
  3. Mint a token for the invoker account. Use the service URL as the audience, call the version route, and expect the digest the pipeline recorded. A token minted for the tag URL fails here even when the request targets the right revision.
  4. Remove the invoker binding. Call again and expect 403 with no invocation, then restore the binding. Allow propagation before deciding the grant is wrong.
  5. Publish one message. Expect one record, one acknowledgement and an empty dead-letter topic. Note the message id from the log, not from the payload.
  6. Write, then fail. Make the handler store the record and return an error, publish one message, and expect two deliveries. One record is idempotency; two records is the defect the key was meant to prevent.
  7. Fail every attempt. Send a message the handler always rejects and expect it on the dead-letter topic at the configured attempt count, with a readable reason.
  8. Upload one object. Expect a CloudEvent with the bucket and object name. Then point a trigger at a bucket outside its location and expect the API to refuse the mismatch.
  9. Run the job from the schedule. Call the jobs API with an OAuth token and expect an execution; swap in an OIDC token and expect the API to reject it.
  10. Destroy and inspect. Apply a reviewed destroy plan, then list revisions, topics, subscriptions, the trigger, the scheduler job and the service accounts instead of assuming the project is clean.

Expected observation. A sequence rather than a duration: a 401 with no container log, a 200 with the recorded digest, a 403 after the binding is removed, one event with one record, two deliveries with one record, a dead-letter message at the configured count, one delivered storage event, and a rejected token type.

Failure checks. The lab fails if a denied caller still reaches the revision, if the retry creates a second record, if the dead-letter topic receives a message the handler reported as successful, or if the version route reports a digest the pipeline did not record.

Cleanup. Delete the trigger and subscription before the topics they use, delete the scheduler job before the identity it impersonates, and remove the service and job before the Artifact Registry repository. Keep the release record and the last digest until the rollback window closes.

Evidence to keep. The digest from the version route, the service URL and revision name, the binding scope for each identity, the two delivery counts, the dead-letter reason, and one redacted request log line per outcome.

References (verified 6 November 2026):

  • google_cloud_run_v2_service: https://registry.terraform.io/providers/hashicorp/google/8.10.0/docs/resources/cloud_run_v2_service
  • google_cloud_run_v2_job: https://registry.terraform.io/providers/hashicorp/google/8.10.0/docs/resources/cloud_run_v2_job
  • google_cloudfunctions2_function: https://registry.terraform.io/providers/hashicorp/google/8.10.0/docs/resources/cloudfunctions2_function
  • google_eventarc_trigger: https://registry.terraform.io/providers/hashicorp/google/8.10.0/docs/resources/eventarc_trigger
  • google_pubsub_subscription: https://registry.terraform.io/providers/hashicorp/google/8.10.0/docs/resources/pubsub_subscription
  • google_cloud_scheduler_job: https://registry.terraform.io/providers/hashicorp/google/8.10.0/docs/resources/cloud_scheduler_job
  • Cloud Run functions comparison: https://cloud.google.com/functions/docs/concepts/version-comparison
  • Cloud Run request timeout: https://cloud.google.com/run/docs/configuring/request-timeout
  • Cloud Run ingress: https://cloud.google.com/run/docs/securing/ingress
  • Pub/Sub push to Cloud Run: https://cloud.google.com/run/docs/triggering/pubsub-push
  • Eventarc trigger creation and retry: https://cloud.google.com/eventarc/docs/creating-triggers
  • Cloud Scheduler HTTP authentication: https://cloud.google.com/scheduler/docs/http-target-auth

Next in the Series

In GKE and Artifact Registry: Cluster Infrastructure and Workload Boundaries, we'll explore Stage managed cluster provisioning before Kubernetes API operations and keep identities and images explicit.