Back to Terraform

Capstone I: Operate a Governed Google Cloud Application

November 6, 2026 Wasil Zafar 43 min read

Build a small Cloud Run or VM-based application with narrow IAM and recoverable data ownership.

Table of Contents

  1. Define the Minimal Service and Its Cost Boundary
  2. Partition Identity, State, Artifacts and Data Ownership
  3. Promote a Reviewed Plan and Immutable Application Artifact
  4. Prove the Service Through Positive and Negative Cases
  5. Recover a Controlled Failure and Submit the Evidence

Define the Minimal Service and Its Cost Boundary

A capstone is a release a reviewer can reject. You build one small note service, split it across three roots, prove it with positive and negative cases, promote one immutable image, break it once on purpose, and hand over six deliverables. The system is deliberately dull; the evidence is the work.

IDDeliverableAccepted when
D1Scope and cost recordone service, one region, a USD 5 ceiling and its stop rules
D2Ownership matrixevery object has one root, one state prefix and one credential scope
D3Three applied rootsbootstrap, data and service plan and apply with no console edits
D4Promotion recordplan digest and image digest approved together, applied once
D5Acceptance matrixpositive and negative cases recorded with their evidence source
D6Recovery and cleanup reportone controlled failure recovered, three no-change plans, an inventory

The service is a note store behind Cloud Run. Five routes, one bucket, one image. A caller writes a note, reads it back by id, and asks whether the process is alive or actually ready. Nothing is public, and no route is anonymous.

RouteMethodData callWhat it proves
/notesPOSTwrites one objectthe write path and the bucket prefix
/notes/{id}GETreads one objectthe read path and the not-found branch
/healthGETnonethe process is running
/readyGETone sentinel readidentity, bucket and network all work
/versionGETnonethe running image carries the promoted digest

Authorization is IAM, not a shared token. Cloud Run checks the invoker role before the container starts, so an unsigned request never reaches your code. That decision gives the negative test a precise expected result and keeps the identity surface inside the ownership matrix.

Private here means no public data plane. Ingress is internal-only, the bucket blocks public access, and the registry is private. The trade is explicit: no load balancer, no custom domain and no VPC connector, because each one would add a network proof and a line item to a project that only has 72 hours.

ChoiceWhat Terraform recordsRollback unitCost note
Cloud Run serviceimage digest, revision template, ingressprevious digestscales to zero, billed per request
GCE managed instance groupinstance template with the image digestprevious templatea VM runs whether or not it is called

Choose one path before the first credential. Cloud Run is the reference path; a single-instance managed group is the accepted substitute and changes the network proof, the probe set and the idle cost, not the ownership model.

The cost ceiling is a number with stop rules, not a hope. Write USD 5 for a 72-hour window into the scope record, then bound each driver that could reach it. A budget alert is a lagging signal, so the stop rules are what actually end the spend.

DriverBound written into the scope recordWhat breaks the ceiling
Cloud Runmax 3 instances, 1 CPU, 512 MiB, 30-second timeouta retry loop, or min instances left at 1
Storageone bucket, notes prefix only, no cross-region copya second bucket, or a large object per request
Registryone repository, cleanup keeps 10 digestsan image per commit and no cleanup policy
Logs30-day retention, no request bodiesdebug lines that print note text
Networkno load balancer, no NAT, no VPC connectorattaching the service to a VPC for a demo
Keysnone in version onea key per resource for a 72-hour lab

Prerequisites are checks with a stop condition. A prerequisite that fails quietly at apply time becomes a mystery during acceptance, so each row carries the decision to stop.

PrerequisiteHow to verifyIf it fails
Billing linked to one projectthe billing page shows the projectstop, do not create resources
Run, Registry, Storage and IAM APIsa read-only list of enabled servicesstop, or ask the platform owner
A region that offers both productsthe region appears for Cloud Run and for the bucketchange region before applying
Quota above the instance ceilingthe quota page shows headroom above 3lower the ceiling before applying
Permission to manage IAM, budget and logsa read-only dry run of the planrequest the role, record the delay
A named reviewer and approverboth names in D1the capstone has no gate

Scope is two lists, and the exclusion list is the useful one. "The service" cannot fail a test, while "one route set, one bucket, one image" can.

BoundaryIncludedExcluded
Trafficinternal ingress, default run.app URL, platform TLScustom domain, load balancer, Cloud Armor
Computeone service, 3 instances maximum, scale to zerojobs, functions, GKE, a second fleet
Dataone bucket, versioning, 7-day soft deleteCloud SQL, Firestore, cross-region replication
Operationsone log-based metric, one alert policy, one budgetan on-call rotation, a status page, tracing

Figure 1 is the decision the scope record has to make before a credential exists.

Define the Minimal Service and Its Cost Boundary
%%{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["Scope record
one region, one service, one bucket"] --> P{"Implementation path
Cloud Run or managed group?"} P -->|"Cloud Run"| C["Service and revision
image by digest"] P -->|"managed group"| M["Instance template
image by digest"] C --> Q{"Prerequisites met
billing, APIs, quota?"} M --> Q Q -->|"no"| X1["Stop
no credential issued"] Q -->|"yes"| B["Cost ceiling
USD 5 and stop rules"] B --> R{"Reviewer accepts D1?"} R -->|"no"| X1 R -->|"yes"| A["Three roots to build
bootstrap, data, service"] 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 primary; class C,M,B secondary; class P,Q,R warn; class A ok; class X1 danger;

Figure 2 draws the boundary that record describes: a build plane that produces bytes, a runtime plane that answers requests, and a data plane that outlives both.

Build, runtime and data planes for one governed Cloud Run service The bootstrap root holds the state bucket, the service activations, the artifact registry, the budget and both service accounts. The service root holds the Cloud Run service with an internal ingress and a digest-pinned image, a probe pair, an invoker binding, a log metric and an alert. The data root holds one bucket with versioning, soft delete and a fourteen-day noncurrent window. The registry hands a digest to the revision and the data root hands a bucket name to the service. Three planes, three roots, one release Terraform owns the references. The build owns the bytes. The bucket owns the data. Bootstrap root State bucket versioned, soft delete, guarded Service activations platform-owned, keep on destroy Artifact registry immutable tags, 10 digests Budget and identities ceiling, runtime and invoker Service root Cloud Run service internal ingress, digest pinned Revision and probes startup, liveness, 3 instances Invoker binding one account, this service only Metric and alert owned here, 30-day retention Data root One bucket uniform access, no public Versioning and soft delete the recovery window Lifecycle rule noncurrent versions: 14 days One writer the runtime identity, nobody else digest bucket Ceiling: one region, three instances, one bucket, no load balancer, USD 5 for 72 hours. Acceptance starts at the first request, not at a green apply. A clean plan proves nothing about the data plane.

The boundary is what makes the evidence readable. Each plane fails in its own vocabulary: a build failure names a digest, a runtime failure names a revision, and a data failure names a bucket or a permission. Keeping those owners apart is what lets one denial point at one root.

Partition Identity, State, Artifacts and Data Ownership

Three roots exist because three things fail differently. A workload destroy must not remove the state that describes it, a data restore must not require a service release, and an artifact rollback must not depend on the stack that consumes it. Split by lifetime and by verb, not by folder convenience.

Projects are a second, coarser boundary, and one project is enough here. A single sandbox project keeps one billing account, one quota pool and one activation set inside a 72-hour window. Production usually moves the platform surfaces into their own project, and the table says what moves.

SurfaceCapstoneProduction shapeWhat changes
State, registry, activations, budgetone projecta platform projectthe workload consumes the registry path
Service, revision and identitiessame projecta workload projectcross-project act-as and invoker grants
Data bucket and lifecyclesame projecta data projecta bucket-level grant, not a project role
Network paththe defaulta Shared VPC hostthe ingress and private-path proofs

A project split changes who may enable an API and whose quota is consumed. It does not decide which root owns an object, and it does not replace a state prefix. A team that splits projects and keeps one root has moved the blast radius without moving the evidence.

The backend is the first root and the last thing you delete. The bootstrap root creates one bucket with versioning, uniform bucket-level access, enforced public access prevention, a seven-day soft-delete policy and a destroy guard. The GCS backend locks state itself, so there is no lock table to create, pay for, or forget to clean up.

Backend recovery is a read, not a rebuild. Restoring a previous state object generation uses the bootstrap identity while the service keeps serving. A root that keeps state and workload under one owner has no such path: the destroy that removed the resources also removed the record of them.

Identity is partitioned by verb. Six identities, six jobs, six lifetimes. If the identity that plans can also apply, the approval step is decorative.

IdentityUsed byMay doMust not do
Bootstrap admina named human, break-glasscreate the bucket, registry, activations and budgetrun the daily applies
Plan identityCI plan jobread the roots, take the lock, write a plan artifactmutate a resource
Apply identityCI apply jobapply one saved plan, act as the runtime identitywiden a role or edit the backend
Build identityimage build jobpush to one repositorydeploy, or read the data bucket
Runtime identitythe Cloud Run revisionread and write the notes prefix, write logstouch the state bucket or the registry
Invoker identitythe test callerinvoke this service onlyread data, or invoke anything else

The runtime identity is a scoped writer, not a project administrator. Grant object administration on the one data bucket and nothing at project level. A project-wide storage role would make the denial case impossible to construct, which is exactly why the negative test is written before the grant.

A cross-root reference is a variable, never a state read. The data root publishes the bucket name, and the service root consumes it through a tfvars file recorded in the promotion record. Reading the other root's state would give the service root a transitive read of everything the data root holds.

The registry lives in the bootstrap root for a reason. If it sat inside the service root, destroying the service would delete the rollback targets, and a bad release would be unrollable at the worst moment. Immutable tags, a cleanup policy that keeps ten digests and a delete guard make the registry a durable surface with its own owner.

Data ownership includes the delete decision. The bucket has versioning and soft delete from the first apply, and a lifecycle rule expires noncurrent versions after fourteen days, so the recovery window is written down rather than assumed. A retention policy is deliberately excluded because it would block the teardown inside the lab window.

The module contract is shared; the backend is not. All three roots accept the same five inputs (project, region, name prefix, labels and owner) and return the same shape of outputs. No module creates the state bucket, and no module reads another root's state, so a module change cannot move a boundary.

State prefixes are named for the boundary. One prefix per root, one workspace per root, and the environment is a project rather than a workspace selector. A workspace matrix inside one root shares a lock, a key and a blast radius across environments that were meant to be separate.

ObjectRootState prefixCredential scopeRuntime owner
State bucket and lockBootstrapbootstrap/platformobject admin on one bucketplatform
Activations, registry, budgetBootstrapbootstrap/platformservice usage, registry, billingplatform
Runtime and invoker identitiesBootstrapbootstrap/platformIAM on two accountsplatform
Data bucket and lifecycleDatadata/prodstorage admin on one bucketdata
Service, revision, probesServiceservice/prodrun admin, act as the runtimeservice
Metric, alert, invoker bindingServiceservice/prodlogging, monitoring, IAMservice

Figure 3 assigns one owner to each surface and turns every cross-root dependency into a named artifact.

Ownership map across the bootstrap, service and data roots The bootstrap root owns the state bucket, the activations, the registry, the budget and both service accounts. The service root owns the Cloud Run service, its probes, the invoker binding, the metric and the alert. The data root owns one bucket with versioning, soft delete and lifecycle, and grants the runtime identity. Handoffs are a digest and a bucket name passed as variables, never a state read. One owner per object, artifacts across the boundary A shared credential or a duplicated resource is an ownership bug, not a convenience. Bootstrap root bootstrap/platform State bucket versions, soft delete, guard Activations keep on destroy Registry immutable, 10 digests Accounts, budget runtime, invoker, ceiling Service root service/prod Cloud Run service internal ingress, by digest Revision and probes startup and liveness Invoker binding one account, one service Metric and alert error marker, one policy Data root data/prod One bucket notes prefix only Recovery settings versioning, 7-day soft delete Lifecycle window 14 days of noncurrent versions One grant the runtime identity only digest bucket Handoff artifacts Bootstrap exports the registry path and the runtime email. Data exports the bucket name. Service exports the URL and the revision name. Nothing is read from another root's state. Two writers A bucket policy declared in both the data and service roots reverts on alternate applies. The plan looks like drift, and the team learns to ignore the plan.

Read the map in both directions. Every box has exactly one root, and every arrow is a variable or an artifact. An arrow that carries a credential means the boundary leaked, even while the plans stay clean.

Figure 4 follows the mechanics, including the branches that produce a valid plan with the wrong owner.

Partition Identity, State, Artifacts and Data Ownership
%%{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
    B["Bootstrap root
bucket, activations, registry, accounts"] --> K["One state prefix per root
bootstrap, data, service"] K --> D["Apply data root
bucket, lifecycle, runtime grant"] D --> O["Outputs
bucket name, runtime email"] O --> S["Plan service root
service, probes, invoker grant"] S --> A{"Plan touches
another root's object?"} A -->|"yes"| X1["Stop
ownership leak"] A -->|"no"| L{"Backend reachable
and lock acquired?"} L -->|"no"| X2["Apply blocked
state untouched"] L -->|"yes"| AP["Apply service root"] AP --> OK["Three roots applied
one image digest"] D -.->|"destroyed before the service"| X3["Revision points at
a missing bucket"] B -.->|"destroyed with the workload"| X4["State lost with
the thing it described"] 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 B,AP primary; class K,D,O,S secondary; class A,L warn; class OK ok; class X1,X2,X3,X4 danger;

A shared object is a bug that presents as drift. Two roots declaring one policy alternate ownership forever, and each apply looks like the other team's mistake. The symptom table is the fastest way to name the collapsed boundary.

SymptomCollapsed boundaryFirst evidence
A plan rewrites a bucket the service did not createboth roots declare the bucketthe plan address list
Init fails after the workload is gonethe state bucket lived in the workload rootthe backend error at init
Rollback target missing after a teardownthe registry lived in the service rootan empty repository
Apply denied only on some daysone credential shared by three jobsthe caller identity in the error

The matrix is reviewed before the first credential. A boundary that only exists in a diagram is a preference. The matrix is what an operator reads at three in the morning, when the question is who owns the bucket and who may restore it.

Promote a Reviewed Plan and Immutable Application Artifact

Promotion is two digests and one signature. The image digest is what ran the tests; the plan digest is what describes the infrastructure change; the signature covers both at the same moment. A plan approved against one digest and applied with another is an unreviewed deployment with a reviewed filename.

FieldWhat it recordsWhy it matters
Commit and treethe configuration that was revieweda moved branch invalidates the plan
ToolchainTerraform 1.17.1, hashicorp/google 8.10.0a different producer makes a different plan
Lock filecommitted provider selections and hashesa silent provider upgrade changes behaviour
Plan digestthe SHA-256 of the saved plan filethe applied bytes match the reviewed bytes
Image digestthe immutable artifact that ran the teststhe tested code is the promoted code
Revision namethe revision the service reportsthe record names a server, not a hope
Data contractbucket name, prefix and locationa stale contract plans against the wrong bucket
Approver and expirya named human and a deadlineapproval is for a change, not for a season

Pin the producer, not just the product. Every root constrains Terraform to 1.17.1 and the provider to 8.10.0, and every root commits its lock file. The CI runner image is pinned by digest too, because a plan from a different Terraform build is a different plan even when the source is identical.

The artifact is immutable before Terraform sees it. The registry refuses tag reuse, the service references a digest, and latest appears nowhere. A rebuild produces a new digest and therefore a new release; a moved tag is not a release, it is a coincidence.

Plan and apply are separate jobs with separate identities. The plan file is encrypted, readable by the named reviewers and the apply identity, and retained for the rollback window. The apply job re-checks the digest and the approval expiry before it configures the provider, so a stale approval fails before it can change anything.

OrderCommand shapeWhat it produces or proves
1terraform init -backend-config=backend/prod.hclthe root bound to its own prefix
2terraform plan -out=tfplanthe reviewed change, saved
3terraform show -json tfplanthe machine-readable record
4shasum -a 256 tfplanthe digest the approver signs
5terraform apply tfplanexactly the reviewed bytes
6terraform plan -detailed-exitcode0 means no drift, 2 means a diff

The order across roots is part of the design. Apply bootstrap, then data, then service; destroy service, then data, then bootstrap. The data root consumes the runtime identity from the bootstrap root, and the service consumes the bucket name from the data root, so reversing either direction plans against a name that does not exist yet.

There is no schema migration in version one, and that is a decision. The note shape lives in the application, so changing a field is an image release with its own digest. Changing the object key layout is a data migration with a copy step, never an in-place assumption, because the application reads whatever prefix the plan declares.

A saved plan is a secret. It can carry variable values and data source results in clear text, so it is stored as a private, encrypted object with a short expiry. Attaching a plan file to a ticket publishes everything the plan read.

The promotion record is written before the apply and completed after it. The approver, the expiry and both digests go in first; the observed revision name and timestamp go in second. A record reconstructed from memory at the end of the day is a story with a hash in it.

Figure 5 contrasts the promoted path with the two shortcuts that pass a review without earning it: re-planning after approval, and a credential wider than the root.

Promoted artifact path compared with re-planning and a broad credential The promoted path builds an image, records its digest, produces a saved plan, approves the plan digest, applies the saved plan and verifies the digest at the version route. The rejected path approves one plan, re-plans after approval, applies a change nobody reviewed, and relies on a credential wider than the root. Promote the reviewed bytes, not the latest diff Approval attaches to two digests. If either moves after approval, the approval is void. Promoted path Build image digest recorded Plan and save digest recorded Two-person review both digests signed Apply saved plan no re-plan Runtime verification version route returns the approved digest Rejected path Approve plan v1 the review is real Re-plan after approval is stale Apply plan v2 nobody reviewed it Broad credential one role, every root Reviewed filename, unreviewed change a second account is one mistaken apply away A saved plan expires. When it does, the change needs a new plan, a new digest and a new approval. The apply job checks approval, expiry and digest before the provider is configured.

Rollback is a digest and a variable. The registry kept the previous image and the plan was saved, so rollback is a new plan that changes one input to the previous digest. It is still a reviewed change, simply one with a known-good destination and no rebuild.

Prove the Service Through Positive and Negative Cases

Apply success is the beginning of the evidence. The matrix below is the acceptance test, run against the deployed service with the deployed identities. A case that records a status without naming the layer that produced it is an anecdote.

IDCaseActionExpected resultEvidence source
P1Authorized writePOST one note as the invoker201, one object under the prefixresponse and bucket listing
P2Authorized readGET the same id200 with the stored bodyresponse body
P3LivenessGET the health route200, no data callrevision log line
P4ReadinessGET the ready route200 after one sentinel readrevision log and latency
P5VersionGET the version routethe digest the plan recordedresponse body
N1No tokenrepeat P2 without a token401 before the containerrequest log, empty revision log
N2No invoker grantrepeat P2 without the role403 before the containerrequest log, empty revision log
N3Outside ingresscall from outside the projectrefused at the edge, no revisionrequest log, empty revision log
N4Insufficient data rolereplace the grant with viewer, then write500 naming the create permissionrevision log and error metric
N5Disabled APIdisable the Storage API, then read500 naming the disabled APIrevision log and service state

The layer that answers names the control. A 401 is authentication, a 403 at the edge is authorization, a 403 from the storage API is a missing grant, and an API-disabled error is a platform control that no root here owns. Five results, five owners.

ResultDecided byOwnerFirst place to look
401Cloud Run authenticationservicethe token, its audience and expiry
403 before the containerthe service's IAM policyservicethe invoker binding and its scope
refused at the edgeinternal ingressservicethe caller's network path
500 with a storage denialthe bucket policydatathe runtime member on the bucket
500 naming a disabled APIservice activationplatformthe activation owner and the window

Readiness is a data-plane claim, so it has to touch data. The health route proves the process is up; the ready route performs one read against a sentinel object. Without that read, a healthy process and a broken grant produce the same green check.

Telemetry is owned before the first request. Terraform creates the log-based metric and the alert policy, so the service does not create an unmanaged twin with no expiry. The metric matches the application's error marker, and the alert watches that metric rather than the request count.

A disabled API is a negative case with a blast radius. Disable the Storage API inside a written window, call the ready route, and expect a data-plane failure that names the API rather than the bucket. The workload identity cannot disable it, and the platform root sets deletion_policy to PREVENT on the activation, so the test needs a named operator and a re-enable step.

The disabled-API case also proves the activation boundary. The same attempt from the apply identity must fail with a permission error, which is the evidence that a workload root did not inherit the platform's service-usage role. Two outcomes from one action: the data plane breaks, and the control plane refuses to be moved by the wrong owner.

Every negative case names its control. Record the role, the ingress setting or the activation that produced the refusal. A 403 from the wrong rule passes the status check and fails the design, and the next reader cannot tell the difference.

Run the matrix twice. The first run proves behaviour; the second, after a no-change plan in all three roots, proves that nothing moved underneath the passing result. A case that passes only on the first run is a timing dependency wearing a green tick.

Figure 6 places the outcomes on one path and shows which layer answers each one.

Five request outcomes and the layer that decides each one Rows map each request to the gate that decides it and to one outcome. An authorized request passes ingress, token and invoker checks at the Cloud Run edge and returns 200 with a revision log. A request without a token gets 401 at the edge. A valid identity without the invoker role gets 403 at the edge. A request from outside the project is refused at the edge with no revision log. A revision whose bucket grant was removed, or which calls a disabled API, returns 500 with a reason in the revision log and metric. One path, five outcomes, four owners The status code names the layer only if you also record where it was produced. Authorized call P1 to P5 No token N1 No invoker role N2 Outside project N3 Grant or API gone N4 and N5 Cloud Run edge ingress admission token authentication invoker authorization decides 401, 403 and the edge refusal Revision runtime identity one sentinel read 200 with the body revision log 401 at the edge request log only 403 at the edge request log only refused at the edge no revision log 500 with a reason revision log and metric Where the evidence is An empty revision log means the edge decided. A 500 with a storage denial is a data grant. A 500 naming an API is an activation. A 404 is the app, not the platform. A 200 proves only the happy path. Record the layer, not just the number. A negative case is evidence only when it names the control, the layer and the request.

Figure 7 turns the matrix into the evidence flow, including the branch where a passing test produces nothing a reviewer can use.

Prove the Service Through Positive and Negative Cases
%%{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
    B["Baseline
authorized 201 and 200"] --> P["Positive cases
write, read, health, ready, version"] P --> N["Negative cases
no token, no role, outside ingress"] N --> A["Disabled API window
storage activation off"] A --> R{"Readiness failed
for the named reason?"} R -->|"no"| X1["Re-test
the control is unproven"] R -->|"yes"| T{"Telemetry names
the deciding layer?"} T -->|"no"| X2["Fix the metric
before acceptance"] T -->|"yes"| E["Evidence table
one row per case"] E --> G{"Any case red?"} G -->|"yes"| X3["Stop
no promotion"] G -->|"no"| OK["Acceptance signed
D5 complete"] E -.->|"status only, no source"| X4["Unusable evidence
cannot name the control"] 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 B,P,N primary; class A,E secondary; class R,T,G warn; class OK ok; class X1,X2,X3,X4 danger;

A passing matrix is not a promoted service. Acceptance closes when the matrix, the promotion record and the three no-change plans exist together. Each one covers a different failure: behaviour, provenance and drift.

Recover a Controlled Failure and Submit the Evidence

Choose one failure that crosses a root boundary. Remove the runtime identity's object binding on the data bucket in the console. Nothing in the service root changes, the architecture stays intact, and the next write fails inside the container. That is precisely the failure an apply-only review cannot see.

LayerBefore the editAfter the editTerraform view
Serviceauthorized write returns 201the same route returns 500no change
Revision logno deniala storage permission denialno change
Data root planno changesone bucket IAM changedrift found
Service root planno changesno changesboundary held
Alertquietthe error metric breachesone notification

State the hypothesis before you touch anything. Expected: a 500 from the revision, a denial naming the permission, no diff in the service root, exactly one diff in the data root. A hypothesis that cannot be wrong is not a test, it is a description.

Inject with a console edit, not a commit. A commit makes the change legitimate and the plan clean; a console edit is drift by definition, so the plan becomes the detector rather than the change. Record the edit time as the start of the timeline.

Recovery is an apply, not a console reversal. Re-apply the data root to restore the declared binding, then send the authorized write again and record the first success. Reversing the edit by hand restores service without proving that the declared state is authoritative.

Decide what happens to the data before fixing the configuration. The injected failure loses no committed write, so the decision is to repair rather than restore. Write it down, because "we did not need the version history" is a claim the failure has to justify.

OptionRight whenChosen here
Repair the configurationno object version was lostyes, one apply
Restore an earlier generationan object was overwritten or deletedno, path recorded
Rebuild the bucket and repopulatethe bucket itself is unusableno, out of scope
Accept the gapthe data is reproduciblerejected, data is the point

A generation restore is not a repair. Restoring an earlier object creates a new generation; it does not make the deleted bytes current in place. Repointing the application at a restored key is an application change with its own image digest, so the path is recorded as the untested alternative, not run during a permissions incident.

Reconcile all three roots, not just the two involved. Recovery is complete when the data and service roots plan no change, and the bootstrap root plans no change as well. A diff in the bootstrap root after a workload incident means the fix reached the platform surface, which is a different review.

Cleanup is an ordered inventory with a named owner. Each row has an owner and a verification, because "destroy everything" is not a step anyone can check.

OrderObjectOwnerVerified by
1Test callers and their tokensservicethe old caller now gets 401
2Service root: service, IAM, metric, alertservicethe destroy plan applies with zero to add
3Logs exported, then the log bucketserviceevidence archived before deletion
4Data root: versioning and lifecycle removed in a reviewed changedatathe plan states the change
5Objects, versions, then the bucketdataa listing returns nothing
6Images, then the registryreleasethe repository reports zero images
7Budget, then the accountsplatformthe budget is gone, the accounts unused
8State prefixes, then the state bucketplatformno objects, then the guard removed last

Two rows need a human with break-glass. The state bucket carries a destroy guard, and the registry refuses to delete while images exist. Both frictions are deliberate: a teardown that succeeds silently is how the next project inherits a bill and an orphan.

Lab

Recover a Controlled Failure and Submit the Evidence

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

Prerequisites. One sandbox project with billing linked, permission to manage IAM, Run, Storage, Logging and Budgets on that project only, a reviewed D1 with a USD 5 ceiling, one Artifact Registry repository holding the test image, permission to disable the Storage API inside a written window, and a named reviewer plus a named approver. Keep an organization-level administrator outside the lab root as the recovery path.

Deliverables to attach. D1 scope and cost record, D2 ownership matrix, D3 three applied roots, D4 promotion record, D5 acceptance matrix, D6 recovery and cleanup report. The review is not complete until every acceptance row has an artifact behind it.

StageActionPass condition
Preflightplan bootstrap, then data, then servicethree plans, digests recorded, no unexpected destroys
Applyapply in the same orderthree applies, no console edit
Positivewrite, read, health, ready, version201, 200, 200, 200, the recorded digest
Negativeno token, no role, outside ingress401, 403, refused, empty revision logs
Data denialreplace the grant with viewer, then write500 naming the create permission
Disabled APIdisable Storage, call ready, re-enablea 500 naming the API, then recovery
Promotionapprove both digests and apply the saved planone apply of the reviewed bytes
Failureremove the binding during the window500, service plan clean, data plan one change
Recoveryapply the data root, repeat the write201, first success timestamped
Reconciledetailed exit code in all three roots0 three times
Teardownfollow the inventory in orderevery row verified, no leftovers
  1. Record the baseline. Send one authorized write, one authorized read and one ready call; save the request ids and the three plan digests. Do not continue until the baseline is boring.
  2. Prove the positive path. Walk P1 to P5. A red positive case stops the review before any failure injection, because a broken baseline makes recovery unreadable.
  3. Prove the identity negatives. Walk N1 and N2, and record for each whether a revision log line exists. A 403 with an empty revision log is proof that the platform, not the code, refused the call.
  4. Prove the network negative. Call the URL from outside the project and expect the edge to refuse before routing. Record the status the platform returns rather than the one you expected.
  5. Prove the data negative. Replace the runtime member's object administration with viewer, write a note, and record the 500 and the denied permission. Restore the grant with the data root before moving on.
  6. Prove the disabled-API case. In the written window, disable the Storage API, call the ready route, and record the failure naming the API. Re-enable it, then confirm the ready route recovers and the apply identity was refused the disable.
  7. Promote. Approve the plan digest and the image digest, apply the saved plan, and confirm the version route reports the approved digest. Record both digests in D4 before the apply and the revision name after it.
  8. Announce the failure window. Name the expected signal, the recovery owner and the rollback decision. The window is short, and the announcement is what makes the timeline credible later.
  9. Inject the failure. In the console, remove the runtime identity's object binding on the data bucket. Record the time, the actor and the exact binding, then stop editing.
  10. Observe. Send the authorized write and record the 500, the denial and the request id. Run a plan in the service root and expect no changes, then in the data root and expect exactly one.
  11. Recover and reconcile. Apply the data root, repeat the write, and record the first 201 as the recovery timestamp. Then run the detailed exit code in all three roots and expect 0.
  12. Teardown. Follow the inventory in order, archive the evidence before deleting the logs, and finish with a project inventory that returns nothing but the shared activations.

Expected observation. A sequence rather than a duration: 201 then 200, a 401 and a 403 with empty revision logs, an edge refusal with no revision, a 500 naming the storage permission, a 500 naming the disabled API, the promoted digest from the version route, a clean service plan during the incident, exactly one data plan, and three exit codes of 0.

Failure checks. The review fails if a denied caller reaches the revision, if the incident produces a diff in the service root, if the disabled-API error is cleared by widening a role, if the denial never appears in the owned metric, if the acceptance matrix records statuses without the deciding layer, or if any root still shows a diff at the end.

Cost boundary. One Cloud Run service at 1 CPU and 512 MiB with at most 3 instances, one bucket with versioning and soft delete, one repository, one log-based metric, one alert policy, one budget, and egress only through the default URL. The ceiling is USD 5 for 72 hours with notifications at half and at the ceiling; the stop rules in D1 end the spend, not the invoice. Confirm current pricing before the apply and keep the test objects small.

Cleanup. Revoke the test callers, destroy the service root, archive and delete the logs, remove versioning and lifecycle in a reviewed data change, delete objects and versions, delete images before the registry, leave the activations enabled under their platform owner, then destroy the budget, the accounts and finally the state bucket after removing its destroy guard. Confirm with a final plan per root and an empty repository.

Evidence to keep. The scope and cost record, the ownership matrix, the three plan digests, the promotion record with both digests and the revision name, the acceptance matrix with its evidence sources, the denial text and request id, the disabled-API window and error, the recovery timestamp, the data decision, the inventory output and the three final no-change plans. Keep the evidence and discard the credentials.

References (verified 6 November 2026): GCS backend, google_cloud_run_v2_service, google_storage_bucket, google_artifact_registry_repository, google_project_service, google_billing_budget, Cloud Run ingress, Cloud Run access control, Object versioning, Soft delete, Repository cleanup policies.

A governed service is a set of owned surfaces with proof at each one. The capstone passes when a reviewer can name the owner of every object, replay the promotion from its two digests, read a negative case and see which control produced it, and watch one failure recover without the service root moving. That is a stronger result than a green apply, and it is the result this project asks you to deliver.