Define the Minimal Service and Its Cost Boundary
A capstone is a release a reviewer can reject. Build one small release-ledger 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.
| ID | Deliverable | Accepted when |
|---|---|---|
| D1 | Scope and cost record | one account, one region, one service, a USD 10 ceiling and its stop rules |
| D2 | Ownership matrix | every object has one root, one state prefix and one credential scope |
| D3 | Three applied roots | platform, data and service plan and apply with no console edits |
| D4 | Promotion record | plan digest and image ID approved together and applied once |
| D5 | Acceptance matrix | positive and negative cases recorded with their evidence source |
| D6 | Recovery and cleanup report | one controlled failure recovered, three no-change plans, an inventory |
The service is a release ledger behind one balancer. A caller posts a release record, reads it back by id, and asks whether the process is alive or actually ready. Nothing is public except the balancer's HTTPS listener, and every route reaches the bucket through the instance's own RAM role.
| Route | Method | Data call | What it proves |
|---|---|---|---|
/releases | POST | writes one object | the write path and the prefix |
/releases/{id} | GET | reads one object | the read path and the not-found branch |
/health | GET | none | the process is running |
/ready | GET | one sentinel read | identity, bucket and network all work |
/version | GET | none | the running image matches the promoted ID |
Storage is OSS, and that choice removes a schema from the project. A release record is one JSON object under a prefix, so the data contract is a key layout rather than a table. Versioning is the recovery mechanism, and the only writer is the runtime role attached to the instance.
The cost boundary is regional because every priced object is regional. The instance, its disk, the balancer, the bucket, the logstore and the key all bill in the region that holds them, and a copy into a second region is a second line rather than a copy of one. Draw the boundary around one region before drawing it around one account.
One zone is a documented limitation, not an oversight. The instance lives in a single zone because a second zone would double the compute bill and add a failover proof this project does not claim. The balancer still needs two vSwitches in two zones, so the second one exists for the listener rather than for the workload. Write that sentence into D1, where the availability claim can be read against the architecture.
A database would add a second recovery contract, so version one has none. Object versioning gives the records a recovery story with one product, one policy and one lifecycle rule. A managed database would add a backup schedule, a connection secret and a restore rehearsal that a 72-hour window cannot absorb. The ledger is small enough that the object store is the honest choice.
Two paths are accepted, and one is the reference. The ECS path is the reference because it exercises a security group, a boot-time identity and a health check the operator can also call. The function path is legitimate and changes the network proof, the probe set and the idle cost, not the ownership model.
| Path | Runtime | What Terraform records | Rollback unit | Cost shape |
|---|---|---|---|---|
| ECS reference | one instance behind an ALB | image ID, listener, server group, instance | the previous image ID | instance hours plus balancer hours |
| Function Compute | one function behind an HTTP trigger | the function's code reference and role | the previous code version | invocations plus duration |
Choose the path before the first credential. A path chosen after the network exists is a rewrite of the plan, the probe set and the identity table at once. The substitute is not a shortcut around the evidence; it is a different set of controls producing the same six deliverables.
Public stops at the balancer. The instance has no public address, reaches OSS and SLS through the region's internal endpoints, and never holds a key. The listener terminates TLS with a certificate created outside Terraform and referenced by ID, which makes the certificate another artifact with its own review record.
What the balancer buys is a name that survives a replacement. A public address on the instance would change with the instance or keep billing after it, and an operator would have to track which one is current. A listener with a certificate gives the caller one hostname, one port and one TLS policy, and it moves the public cost to a resource the service root owns.
The cost ceiling is a number with stop rules, not a hope. Write USD 10 for a 72-hour window into D1, then bound every driver that could reach it. A budget alert is a lagging signal, so the stop rules below are what actually end the spend.
| Driver | Bound written into D1 | What breaks the ceiling |
|---|---|---|
| ECS | one instance, 2 vCPU and 4 GiB, 40 GiB ESSD, pay-as-you-go | a scaling group, or a replacement loop that leaves the old instance billed |
| Balancer | one ALB, one HTTPS listener, one server group | a second listener or a load test that multiplies capacity units |
| Object storage | one bucket under 1 GiB, versioning, a 14-day noncurrent window | versioning without a lifecycle rule |
| Logs | one project, one logstore, 7-day retention, no request bodies | debug lines that print release payloads |
| Images | one custom image and one snapshot, two retained | an image per commit with no retention tag |
| Keys and network | one KMS key, no NAT gateway, no address on the instance | attaching an EIP for SSH, or a NAT gateway for a package download |
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.
| Prerequisite | How to verify | If it fails |
|---|---|---|
| Billing and verification on one account | the account page shows both | stop, nothing billable can be created |
| The region offers ECS, ALB, OSS, SLS, KMS and CloudMonitor | the product list for that region | change region before writing the plan |
| A zone stocks the instance type and disk category | a zone query filtered by both | choose another type or zone and record the query date |
| Two vSwitches in two zones for the balancer | the VPC view shows both | the ALB cannot be created |
| Quota for one instance and one balancer | the quota page shows headroom | request the increase and record the delay |
| A certificate visible from that region | the certificate list shows it | upload one, the listener cannot be created |
| A named reviewer and approver | both names in D1 | the capstone has no gate |
Scope is two lists, and the exclusion list is the useful one. "A small service" cannot fail a test, while "one listener, one instance, one bucket" can.
| Boundary | Included | Excluded |
|---|---|---|
| Traffic | one internet-facing ALB, HTTPS 443, a certificate | a second listener, HTTP redirect, WAF, CDN |
| Compute | one ECS instance from a custom image, one zone | scaling groups, a second instance, containers |
| Data | one OSS bucket, versioning, lifecycle, one bucket policy | a database, cross-region replication, a second bucket |
| Operations | one logstore, one log alert, one alarm, one budget | an on-call rotation, tracing, a status page |
Figure 1 is the decision the scope record has to make before a credential exists.
%%{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 account, one region, one service"] --> P{"Which runtime path
ECS instance or function?"}
P -->|"ECS reference"| E["Instance from a custom image
behind one ALB"]
P -->|"function"| F["Function with an HTTP trigger
no security group"]
E --> Q{"Region offers every product
and the zone stocks the type?"}
F --> Q
Q -->|"no"| X1["Stop
change region or path"]
Q -->|"yes"| C["Cost ceiling
USD 10 and stop rules"]
C --> R{"Reviewer accepts D1?"}
R -->|"no"| X1
R -->|"yes"| A["Three roots to build
platform, 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 E,F,C 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 an image, a runtime plane that answers requests, a data plane that outlives both, and a ceiling drawn around all three.
The boundary is what makes the evidence readable. A build failure names an image, a runtime failure names a listener or an instance, and a data failure names a bucket or a policy statement. 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 image rollback must not depend on the stack that consumes it. Split by lifetime and by verb, not by folder convenience.
One account and one region are enough here, and that is a decision. A single sandbox account keeps one billing account, one quota pool and one audit trail inside 72 hours. Production usually separates the platform surfaces into their own account, and the table says what moves.
| Surface | Capstone | Production shape | What changes |
|---|---|---|---|
| State, lock, keys, CI roles | one account | a platform account | the workload assumes a role across accounts |
| Service, balancer, logs | same account | a workload account | cross-account image sharing and bucket grants |
| Data bucket and policy | same account | a data account | a bucket policy naming a foreign role |
| Audit history | the 90-day event query | an organization trail | the management account owns the destination |
The backend is the first root and the last thing you delete. The platform root creates one OSS bucket with versioning, server-side encryption, a public access block and one prefix per root, plus a Tablestore table for locks. The backend is not a module, and no workload root may create it.
Backend recovery is a read, not a rebuild. State is an object with versions, so restoring a previous version uses the platform 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 removed the record of them.
The state key is encrypted with a key the platform owns, and that creates an order. A disabled key makes the state unreadable, so the recovery runbook enables the key first, then reads. Write the order down; the alternative is an engineer debugging a backend error during an incident.
The lock table is what makes two plans safe. A plan takes the lock for its prefix, and a second run waits or fails instead of reading half-written state. The table is small and cheap, and it is the difference between a serialised pipeline and two applies interleaving writes that neither plan predicted.
Identity is partitioned by verb. Six identities, six jobs, six lifetimes. If the identity that plans can also apply, the approval step is decorative.
No static key pair belongs in this project. The CI jobs assume a role through OIDC, and the instance assumes its role through the metadata service, so no AccessKey pair is written into a workflow file, a user data script or a state file. A pair that exists has to be rotated, and a rotation that touches no plan is the sign of a correct boundary.
| Identity | Used by | May do | Must not do |
|---|---|---|---|
| Platform admin | a named human, break-glass | create the bucket, lock table, key and roles | run the daily applies |
| Plan role | the CI plan job | read the roots, take the lock, write a plan artifact | mutate a resource |
| Apply role | the CI apply job | apply one saved plan, pass the runtime role | edit the backend or widen a policy |
| Build role | the image pipeline | read source, build, publish an image, write the build record | deploy, or read the bucket |
| Runtime role | the ECS instance | put and get under the release prefix, write logs | touch state, keys or images |
| Test reader | the sandbox verifier | read one named object | write, list broadly, or assume the runtime role |
The runtime identity is a scoped writer, not an account administrator. The bucket policy grants put and get on the release prefix and nothing else, and the denial case is written before the grant. A bucket-wide or account-wide grant makes the negative test impossible to construct, which is exactly why it is written first.
A cross-root reference is a variable, never a state read. The data root publishes the bucket name and prefix, and the service root consumes them through a tfvars file recorded in the promotion record. Reading another root's state would give the service root a transitive read of everything that root holds.
The image is owned by the build, and that is why it survives a teardown. The pipeline publishes an image, tags it with the commit and the build number, and keeps two. A destroy in the service root cannot remove the rollback target, because the rollback target was never in that state.
Data ownership includes the delete decision. The bucket has versioning from the first apply and a lifecycle rule that 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 — region, name prefix, owner tag, environment and cost centre — and return the same shape of outputs. No module creates the backend, and no module reads another root's state, so a module change cannot move a boundary.
| Object | Root | State prefix | Credential scope | Runtime owner |
|---|---|---|---|---|
| State bucket and lock table | Platform | platform/bootstrap | object admin on one bucket and one table | platform |
| Key for state and plans | Platform | platform/bootstrap | key administrator on one key | platform |
| CI roles and runtime role | Platform | platform/bootstrap | RAM write on named roles only | platform |
| Custom image and snapshot | Build, outside Terraform | none | image publish on one tag family | build |
| Bucket, versioning, lifecycle, policy | Data | data/prod | bucket admin on one bucket | data |
| VPC, vSwitches, security group, instance, listener | Service | service/prod | VPC, ECS and ALB write | service |
| Logstore, log alert, alarm, contact group | Service | service/prod | SLS and CloudMonitor write | service |
State prefixes are named for the boundary. One prefix per root, one workspace per root, and the environment is the account 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.
Every billable object carries the same ownership tag. The tag is how a Resource Center search after a failed apply finds the disk, address or snapshot that state does not know about. A tag that only some roots set is worse than none, because the inventory looks complete while the orphan stays invisible.
The platform root is applied by a human, not by the pipeline. CI may plan it read-only, but the apply that creates the backend and the roles is a break-glass action with a named operator and a recorded digest. The pipeline that depends on the backend should not be the pipeline that can delete it.
Figure 3 assigns one owner to each surface and turns every cross-root dependency into a named artifact.
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.
%%{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["Platform root
bucket, lock table, key, roles"] --> K["One state prefix per root
platform, data, service"]
K --> D["Apply data root
bucket, lifecycle, runtime grant"]
D --> O["Outputs
bucket name, prefix, region"]
O --> S["Plan service root
network, instance, listener, alarms"]
S --> A{"Plan touches another
root's object?"}
A -->|"yes"| X1["Stop
ownership leak"]
A -->|"no"| L{"Lock acquired and
backend reachable?"}
L -->|"no"| X2["Apply blocked
state untouched"]
L -->|"yes"| AP["Apply service root"]
AP --> OK["Three roots applied
one image ID"]
D -.->|"destroyed before the service"| X3["Listener serves a
bucket that is gone"]
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.
| Symptom | Collapsed boundary | First evidence |
|---|---|---|
| A plan rewrites a policy the data root created | both roots declare the bucket policy | the plan address list |
| Init fails after the workload is gone | the state bucket lived in the workload root | the backend error at init |
| The rollback image is missing after teardown | the build's images were deleted by a destroy | an empty list for the build tag |
| Apply is denied only on some days | one credential shared by three jobs | the caller in the ActionTrail event |
| The listener serves a bucket that no longer exists | data destroyed before service | a 500 naming the missing bucket |
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 identifiers and one signature. The image ID 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 image and applied with another is an unreviewed deployment with a reviewed filename.
| Field | What it records | Why it matters |
|---|---|---|
| Commit and tree | the configuration that was reviewed | a moved branch invalidates the plan |
| Toolchain | Terraform 1.17.1, aliyun/alicloud 2.2.0 | a different producer makes a different plan |
| Lock file | committed provider selections and hashes | a silent provider upgrade changes behaviour |
| Plan digest | the SHA-256 of the saved plan file | the applied bytes match the reviewed bytes |
| Image ID | the immutable image that ran the tests | the tested build is the promoted build |
| Build reference | the commit and build number behind the image | an ID alone does not say what is inside it |
| Data contract | bucket name, prefix and region | a stale contract plans against the wrong bucket |
| Approver and expiry | a named human and a deadline | approval 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 2.2.0, and every root commits its lock file. The CI runner image is pinned too, because a plan from a different Terraform build is a different plan even when the source is identical.
The reviewer reads four things in the plan, not forty. The image ID, the certificate ID, the bucket name and the resource count. A replacement where an update was expected, or a create where a change was expected, is a design question before it is an approval question.
The image is immutable before Terraform sees it. The pipeline publishes one image per commit and the service references the ID, never a name. A name that a pipeline republishes resolves to the newest build at launch, and the plan cannot show which build that is. The build also records the architecture, because an Arm image cannot boot an x86 family.
Retention is part of the artifact contract. Two images per tag family is enough to roll back one release and cheap enough to keep; a third means the pipeline is publishing more often than it is reviewing. The deletion job runs on a schedule and skips the image named in D4.
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.
Approval expires, and that is a feature. A saved plan carries the state serial it was built from, so a stale file cannot be applied after another run moves the prefix. The approval also carries a deadline of its own, and when that passes the change needs a new plan, a new digest and a new signature rather than a forced apply.
| Order | Command shape | What it produces or proves |
|---|---|---|
| 1 | terraform init -backend-config=backend/prod.hcl | the root bound to its own prefix |
| 2 | terraform plan -out=tfplan | the reviewed change, saved |
| 3 | terraform show -json tfplan | the machine-readable record |
| 4 | shasum -a 256 tfplan | the digest the approver signs |
| 5 | terraform apply tfplan | exactly the reviewed bytes |
| 6 | terraform plan -detailed-exitcode | 0 means no drift, 2 means a diff |
The order across roots is part of the design. Apply platform, then data, then service; destroy service, then data, then platform. The data root consumes the runtime role name from the platform 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.
An image change on one instance is a disk swap unless you ask for a replacement. By default the provider stops the instance, rebuilds the system disk from the new image and keeps the address; with replacement enabled the change becomes a destroy and create. Decide which one the lab uses and record it, because the balancer sees a different outage either way.
The disk swap is invisible to the bucket and visible to the balancer. The system disk is rebuilt, so anything cached locally is gone while the release records stay in OSS. The listener sees one unhealthy member for the boot window, which is why the check interval and the boot time belong in the same record.
There is no schema migration in version one, and that is a decision. The record shape lives in the application, so changing a field is an image release with its own ID. Changing the key layout is a data migration with a copy step, never an in-place assumption.
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 identifiers go in first; the observed instance ID and the listener address 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 an image reference that moves.
Rollback is an image ID and one variable. The pipeline kept the previous image and the plan was saved, so rollback is a new plan that changes one input to the previous ID. 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.
| ID | Case | Action | Expected result | Evidence source |
|---|---|---|---|---|
| P1 | Authorized write | post one release as the test caller | 201, one object under the prefix | response and bucket listing |
| P2 | Authorized read | read the same id | 200 with the stored body | response body |
| P3 | Liveness | call the health route | 200, no bucket call | application log line |
| P4 | Readiness | call the ready route | 200 after one sentinel read | application log and latency |
| P5 | Version | call the version route | the image ID the plan recorded | response body |
| N1 | Direct write by the test role | put an object with the CLI | 403 from OSS | the CLI error and the request id |
| N2 | Runtime grant removed | post one release after the edit | 500 naming the denied action | application log and log alert |
| N3 | Plain HTTP on port 80 | call the listener over HTTP | refused, no listener on that port | an empty application log |
| N4 | Direct call to the private address | connect from outside the VPC | timeout or refused | an empty application log |
| N5 | Certificate for another hostname | call the listener with that name | client TLS verification error | client error, empty application log |
The layer that answers names the control. A 403 from OSS is the bucket policy, a 500 inside the service is the same policy seen through the application, and a refused connection is the listener or the absence of a public address. Five results, and each one points at exactly one owner.
| Result | Decided by | Owner | First place to look |
|---|---|---|---|
| 201 or 200 | listener, runtime role and bucket policy | service and data | the request line and the object key |
| 403 from OSS | the bucket policy | data | the principal in the statement |
| 500 naming a denied action | the bucket policy, seen by the service | data | the application log line and the alert |
| Connection refused | the listener port or the missing public address | service | the listener and the instance address |
| TLS verification error | the certificate names and its expiry | service | the certificate record |
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, and the balancer keeps sending traffic to a member that cannot store anything.
The test caller is not the runtime role. A verifier that borrows the runtime identity proves the identity works and proves nothing about who may call the service. Keep a separate caller with the smallest permission that can exercise the routes, and record which identity made each request.
The balancer checks the same route the operator does. Point the server group's health check at the ready path, not at the port, and record the interval and thresholds beside the listener. A check that admits a port admits a process that cannot write, which is the failure this capstone is built to find.
A healthy backend is not a healthy service. The balancer counts the ready route's answer, and the ready route counts one sentinel read. If the sentinel object is deleted, the check fails while every release record is intact, which is the correct failure for a claim about the data plane.
Telemetry is owned before the first request. The service root creates the logstore, the log alert and the alarm, so the service does not create an unmanaged twin with no expiry. The alert watches the application's error marker rather than the request count, because a request count stays green through a total data-plane failure.
Logs carry identifiers, not payloads. The request id, the route, the status and the denied action are enough to join a request to an alert. A release body or an authorization header in the log turns the logstore into a second copy of the data, with a shorter retention and a wider audience.
The version route is the only proof of provenance. A green health check says a process is running; the version route says which image is running. If the answer is not the ID in D4, the apply that reported success promoted something else.
Confirm the metric exists before you build the alarm. CloudMonitor coverage differs by product and region, so check that the balancer's unhealthy-backend metric appears for this listener. If it does not, keep the log alert as the only signal and record the gap in D5 rather than inventing a dashboard.
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.
Figure 7 turns the matrix into the evidence flow, including the branch where a passing test produces nothing a reviewer can use.
%%{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
201 write and 200 read"] --> P["Positive cases
write, read, health, ready, version"]
P --> N["Negative cases
no route, no listener, no grant"]
N --> D["Denied write
runtime role removed from the policy"]
D --> R{"Service answers with
the expected refusal?"}
R -->|"no"| X1["Re-test
the control is unproven"]
R -->|"yes"| T{"Log and alert name
the deciding layer?"}
T -->|"no"| X2["Fix the log alert
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,D primary;
class 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 role from the bucket policy in the console. Nothing in the service root changes, the instance keeps running, and the next write fails inside the process. That is precisely the failure an apply-only review cannot see.
| Layer | Before the edit | After the edit | Terraform view |
|---|---|---|---|
| Service | an authorized write returns 201 | the same route returns 500 | no change |
| Application log | no denial | a denied put action | no change |
| Data plan | no changes | one bucket policy change | drift found |
| Service plan | no changes | no changes | boundary held |
| Alert | quiet | the error marker breaches | one notification |
State the hypothesis before you touch anything. Expected: a 500 from the service, a denial naming the put action, no diff in the service root, exactly one diff in the data root, one alert. A hypothesis that cannot be wrong is a description, not a test.
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.
The edit is recorded even when no trail exists. A bucket policy change is a management event, so the account's 90-day event history names the principal, the time and the request. That record is what turns "someone changed the policy" into a timestamp the timeline can use.
Only the named operator injects, and only inside the window. The announcement names the expected signal and the person who will recover, so a second engineer reading the alert does not start a parallel fix. Two responders editing one policy is how a controlled failure becomes an uncontrolled one.
Recovery is an apply, not a console reversal. Re-apply the data root to restore the declared statement, 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.
Repair and rollback are different promises. Repair restores the declared statement and keeps the release; rollback returns the previous image and starts a new release. This failure needs repair because the image never changed, and calling it a rollback would hide that the data-plane grant was the only thing that moved.
Decide what happens to the data before fixing the configuration. A permissions failure raises the question, and answering it after the apply makes the answer a rationalisation. Write the decision down before the recovery begins, while the failure is still the only thing you know.
Four options exist, and three are wrong for this failure. Repair the configuration when no object version was lost; restore an earlier version when an object was overwritten or deleted; rebuild the bucket when the bucket itself is unusable; accept the gap when the data is reproducible. The injected failure loses no committed object, so the choice is repair with one apply, and the other three are recorded as unexercised paths rather than described as if they had run.
A version restore is not a repair. Resolving an earlier object version makes those bytes current again as a new version; it does not undo the policy that refused the write. Repointing the application at a restored key is an application change with its own image ID, so the path is recorded as the untested alternative rather than 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 platform root plans no change as well. A diff in the platform root after a workload incident means the fix reached the backend, which is a different review.
The timeline is the artifact, not the memory of it. Record the edit time, the first failed request, the first alert, the recovery apply and the first success, each with its source. The gaps between those five times are the review's real findings, and they are impossible to reconstruct the next morning.
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.
| Order | Object | Owner | Verified by |
|---|---|---|---|
| 1 | Test callers and their access | service | the old caller now gets 403 |
| 2 | Listener, server group, instance, security group | service | the destroy plan applies with zero to add |
| 3 | Older build images, keeping the promoted one | build | one image remains for the tag |
| 4 | Log alert, alarm, contact group | service | the alarm history is exported first |
| 5 | Logstore and log project | service | evidence archived before deletion |
| 6 | Lifecycle and versioning removed in a reviewed change | data | the plan states the change |
| 7 | Objects, versions, then the bucket | data | a listing returns nothing |
| 8 | CI roles and the runtime role | platform | the role list shows none of the lab names |
| 9 | Key, with its deletion window recorded | platform | the window and the schedule owner |
| 10 | State prefixes, then the state bucket and lock table | platform | no objects, then the guard removed last |
Two rows need a human with break-glass. The state bucket refuses deletion while objects remain, and the key refuses deletion while protection is on. Both frictions are deliberate: a teardown that succeeds silently is how the next project inherits a bill and an orphan.
Recover a Controlled Failure and Submit the Evidence
Status: design-only. No Alibaba Cloud account or credential was used to produce this capstone, and these steps were not executed here. Versions: Terraform CLI 1.17.1, aliyun/alicloud 2.2.0, verified 6 November 2026. Every identifier below is a placeholder you replace: the account, region, zone, image, certificate and bucket are values you nominate.
Prerequisites. One sandbox account with billing and verification complete, permission to manage VPC, ECS, ALB, OSS, SLS, KMS, RAM and CloudMonitor in one region, a reviewed D1 with a USD 10 ceiling, one custom image holding the service and its build record, one certificate visible from that region, and a named reviewer plus a named approver. Keep an account 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.
| Stage | Action | Pass condition |
|---|---|---|
| Preflight | plan platform, then data, then service | three plans, digests recorded, no unexpected destroys |
| Platform | apply the backend, key and roles | one bucket, one lock table, one key, four roles |
| Backend | move the platform state into the bucket | a second plan is empty and a lock is visible |
| Data | apply the bucket, lifecycle and policy | one bucket, one statement, one principal |
| Service | plan against the recorded outputs | the recorded image ID and certificate ID appear |
| Promotion | approve both identifiers and apply the saved plan | one apply of the reviewed bytes |
| Positive | write, read, health, ready, version | 201, 200, 200, 200, the recorded image ID |
| Negative | direct write, port 80, private address, bad hostname | 403, refused, no route, TLS error |
| Failure | remove the runtime statement during the window | 500, service plan clean, data plan one change |
| Recovery | apply the data root, repeat the write | 201, first success timestamped |
| Reconcile | detailed exit code in all three roots | 0 three times |
| Teardown | follow the inventory in order | every row verified, no leftovers |
- Record the baseline. Write the account, region, zone, instance type, disk category and the day's spend into D1. Run the zone query filtered by type and disk category, and record the query date beside the answer.
- Apply the platform root once with local state. Create the state bucket, the lock table, the key and the four roles. Expect a create of every object and no workload resource, and write the plan digest into D3.
- Move the backend. Copy the platform state into the bucket it created, then enable the backend with one prefix per root. Run a second plan and expect no changes, and confirm a plan takes a lock in the table.
- Apply the data root. One bucket with versioning, a fourteen-day noncurrent window, encryption and one bucket policy naming the runtime role. Record the bucket name, prefix and region as outputs.
- Plan the service root from the recorded outputs. Expect the network, the instance from the image ID, the listener, the server group, the logstore and the alarms, and nothing that touches the bucket policy.
- Read the plan before applying it. Confirm the image ID matches the build record, the certificate ID matches the certificate, the bucket name matches the data output, and no resource replaces something that already serves.
- Promote and apply. Approve the plan digest and the image ID together, apply the saved plan once, and record the instance ID and the listener address in D4.
- 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.
- Prove the denials. Walk N1 to N5 and record where each one was refused. For the cases that never reach the service, an empty application log is proof that a platform control refused the request.
- 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.
- Inject the failure. In the console, remove the runtime role's statement from the bucket policy. Record the time, the actor and the exact statement, then stop editing.
- Observe. Send the authorized write and record the 500 and the denial with its request id. Run a plan in the service root and expect no changes, then in the data root and expect exactly one.
- 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.
- Teardown. Follow the inventory in order, archive the evidence before deleting the logs, and finish with a Resource Center search by the ownership tag that returns nothing billable.
Expected observation. A sequence rather than a duration: 201 then 200, a 403 from OSS with its request id, a refused connection on port 80, no route to the private address, a TLS error for the wrong hostname, a 500 naming the denied action, 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 service, if the incident produces a diff in the service root, if the 500 is cleared by widening an account role instead of restoring the statement, if the denial never appears in the owned alert, if the acceptance matrix records statuses without the deciding layer, or if any root still shows a diff at the end.
Cost boundary. One instance at 2 vCPU and 4 GiB with a 40 GiB disk, one internet-facing ALB with one listener, one bucket under 1 GiB, one logstore at 7-day retention, one key, one image, no NAT gateway and no address on the instance. The ceiling is USD 10 for 72 hours with notifications at half and at the ceiling; confirm current pricing before the apply and let the stop rules in D1 end the spend.
Cleanup. Revoke the test caller, destroy the service root, export the alarm history and then delete the alerts, remove lifecycle and versioning in a reviewed data change, delete objects and versions before the bucket, keep the promoted image until the teardown is accepted, delete the roles, schedule the key with its window recorded, and destroy the state prefixes before the bucket and lock table after removing the guard. Confirm with a final plan per root and an empty Resource Center search.
Evidence to keep. The scope and cost record, the ownership matrix, the three plan digests, the promotion record with both identifiers and the listener address, the acceptance matrix with its evidence sources, the denial text and request id, the failure timeline, 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): alicloud_instance, alicloud_image, alicloud_oss_bucket, alicloud_vpc, alicloud_vswitch, alicloud_security_group, alicloud_ram_role_policy_attachment, alicloud_kms_key, alicloud_alb_server_group, alicloud_log_store, Instance user data.
A reviewed 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 identifiers, read a negative case and see which control produced it, and watch one failure recover without the service root moving.