Back to Terraform

Capstone A: Publish a Small Site with AWS and Cloudflare

November 6, 2026 Wasil Zafar 34 min read

Integrate origin storage, DNS, TLS and scoped identities in a reproducible sandbox deployment

Table of Contents

  1. Choose the Origin and TLS Boundary Before Writing HCL
  2. Define Project-Owned DNS, Storage and Access Resources
  3. Separate Provider Credentials and Backend Access
  4. Plan the Delivery Path and Verify the Endpoint
  5. Review Cost, State and Recovery Evidence
  6. Submit the Architecture, Evidence and Cleanup Record

Choose the Origin and TLS Boundary Before Writing HCL

A capstone is a delivery with a reviewer. You will publish one hostname for a small static site, keep its bytes in a private bucket, terminate TLS at one edge, and prove every hop with a check that can fail on its own. The build is deliberately small; the evidence is the work.

Write the requirements in one paragraph first. The site has one audience, one release cadence, a handful of pages and a rollback window measured in minutes. Freshness matters for the entry document and almost not at all for hashed assets, and the cost ceiling is a few dollars a month.

Each requirement points at exactly one decision. A single audience removes multi-region, a short rollback window argues for immutable releases, and a small cost ceiling rules out a second cache and a WAF subscription. When a requirement changes, the decision it drove has to be reopened rather than quietly stretched.

Write the deliverables before the first resource. A capstone that cannot be rejected on paper cannot be accepted on evidence, so the six rows below are the contract with your reviewer.

IDDeliverableAccepted when
D1Architecture decision recordOrigin, TLS, cache and DNS each have one owner and one rejected alternative
D2Ownership and naming mapEvery resource carries the project prefix, one state key and one credential
D3Working deliveryThe hostname serves the fixture over HTTPS from the private bucket
D4Verification logDNS, TLS, origin refusal, cache and not-found each have a recorded result
D5Cost and state recordBilling dimensions and state contents are listed, with the guardrail named
D6Cleanup recordA reviewed destroy plan, an empty state afterwards, and the zone still present

The first decision is the origin endpoint. S3 offers two shapes with very different security properties, and the choice determines everything downstream.

EndpointTransport and accessWhat it forces
REST endpointHTTPS with SigV4, compatible with OACThe bucket stays private and the edge must sign
Website endpointHTTP only, public read or an IP allowlistThe origin leg is plaintext and the bucket is effectively public

The second decision is who terminates TLS and who caches. Three chains work on paper; only one keeps a single owner for each layer.

ChainTLS terminatorCache ownerVerdict
Proxy to the website endpointCloudflareCloudflareRejected: plaintext origin leg, public bucket
Proxy to CloudFrontCloudflare, then CloudFrontTwo cachesDeferred: valid with a WAF requirement, two acceptance paths
CloudFront with OAC, DNS only at CloudflareCloudFrontCloudFrontChosen: one terminator, one cache, one gate

One constraint settles the proxy question. Cloudflare does not sign origin requests with AWS SigV4, so it cannot authenticate to a private S3 REST endpoint by itself. A proxied path to a private bucket needs a Worker, R2, or CloudFront in between, and each of those is a different project with its own evidence.

The chosen chain gives each layer one owner. Cloudflare answers DNS and holds the zone's delegation and DNSSEC chain for the platform. CloudFront terminates TLS and owns the cache, and OAC is the only thing allowed to read the bucket.

TLS has three requirements and no more. The certificate must cover the hostname, the minimum version must be 1.2 or higher, and the viewer protocol must redirect to HTTPS rather than serve plaintext first. HSTS is a deliberate deferral, because it is hard to reverse once a browser has cached it.

Cache has two requirements, and the second one is easy to miss. One cache means one invalidation, and a short lifetime on the entry document means a release is visible without waiting for an hour. Everything with a content hash in its name can be cached for a year, which is where the transfer saving comes from.

The exclusion list is part of the architecture. WAF rules, bot management, image resizing, custom hostnames and a second region are all reasonable for a larger site and all out of scope here. Writing them down prevents a reviewer from discovering them by accident in the plan.

Name the deferral as clearly as the choice. Proxying Cloudflare in front of CloudFront is a legitimate second version when a WAF or bot-management requirement appears. It adds a second certificate, a second cache and a second invalidation step, so it needs its own acceptance row rather than a quiet toggle.

Choose the Origin and TLS Boundary Before Writing HCL
%%{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','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    S["Site hostname
one name, one zone"] --> O{"Origin endpoint"} O -->|"website endpoint"| W["HTTP only
public read or IP allowlist"] O -->|"REST endpoint"| R["HTTPS with SigV4
private bucket"] W --> X1["Rejected
plaintext origin leg"] R --> T{"Who terminates TLS
and caches?"} T -->|"Cloudflare proxy only"| X2["Blocked
no SigV4 to S3"] T -->|"Cloudflare in front of CloudFront"| D["Deferred
two certificates, two caches"] T -->|"CloudFront with OAC"| C["Chosen
one terminator, one cache"] C --> E["Acceptance
DNS, TLS, refusal, cache"] 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,O,T,R primary; class W secondary; class C,E ok; class X1,X2 danger; class D warn;

Read Figure 1 for the branch that says no. The website endpoint is rejected before any HCL exists, and the proxied path is blocked by a signing constraint rather than a preference. Those two facts are the architecture, not a footnote to it.

Delivery chain and the two rejected paths A visitor resolves the hostname at Cloudflare, connects over TLS to CloudFront, which signs an origin access control request to a private S3 bucket. A proxied Cloudflare path to the S3 website endpoint is rejected because the origin leg is plaintext and the bucket must be public. One chain, one owner per hop The solid path is what you build. The dashed path is what the boundary decision rules out. Visitor public hostname Cloudflare DNS zone, two records DNSSEC chain CloudFront ACM certificate the only cache OAC SigV4 signature always sign S3 bucket private, no ACL release prefixes DNS owner TLS and cache owner origin gate bytes Rejected: proxy to the website endpoint HTTP-only origin leg, public read or an IP allowlist Four checks, four owners Authoritative and recursive DNS answer · served chain and TLS 1.2 · AccessDenied on the direct URL · cache miss then hit No single failure is repaired by changing the other three layers. One terminator, one cache, one gate Cloudflare in front of CloudFront is a valid upgrade, but it doubles both and needs its own proof.

Figure 2 is the map every later check refers to. Each hop has one owner and one observable signal, so a failure at the origin cannot be mistaken for a DNS problem.

Define Project-Owned DNS, Storage and Access Resources

Scope is a prefix plus an exclusion list. Every resource this root creates carries the project prefix, and everything without that prefix is outside the destroy. A reviewer should be able to decide from a name alone whether cleanup may touch it.

The bucket name is identity, so it cannot be invented at apply time. S3 names live in a global namespace, and a rename is a migration rather than an update. Take the unique suffix as a validated input, put purpose and environment in the name, and keep display labels in tags where a change costs nothing.

The zone is an input, never a resource. Pass its identifier as a variable and leave the zone object, its apex records and its DNSSEC signing to the platform owner. If the zone appears in this configuration, one destroy removes DNS for every service that shares it.

Two records are enough, and both are grey. The site record points at the distribution, and the validation record proves the certificate. Everything else in the zone belongs to someone else.

NameTypeProxyOwnerLifecycle
Site hostCNAME to the distributionDNS onlythis projectdestroyed with the site
ACM validationCNAME to the validation valueDNS onlythis projectkept while the certificate lives
Zone apex, mail, other hostsexisting recordsunchangedplatformnever in this root

A proxied validation record is a stalled certificate. ACM asks a public resolver for the validation CNAME, and a proxied record answers with edge addresses instead. Grey-cloud both records, and keep the validation record after issuance, because renewal reuses it.

Key the records by purpose, not by position. A map with keys such as site and validation keeps each address stable when a third record appears, and a for_each over that map means the plan lists one change rather than a renumbered list. If a key is ever renamed, a moved block bridges the old address so the record is updated instead of replaced.

Both records are small enough to review line by line. The site record carries a TTL short enough to change traffic within minutes, and the validation record carries the value ACM returned. Neither one is proxied, and neither one touches the apex.

Storage starts private and stays private. Four controls carry that claim: all four public access flags, bucket-owner-enforced ownership, no ACL grants, and a policy statement that denies non-TLS access. The last one never fires in normal operation, which is exactly why it is cheap insurance.

The bucket policy names one principal and one distribution. The principal is the CloudFront service, and a condition pins the source to this distribution's ARN. A wildcard principal, or a policy without that condition, is a public bucket with extra steps.

Nothing reads the bucket except the edge. There is no list permission for the public, no website endpoint and no second consumer, which is why the policy is one short document instead of a review project. A signed URL for a human to debug with would be a second grant, and it belongs in the change record rather than in the configuration.

Release keys are immutable, and that is what makes caching safe. Each upload lands under a version prefix, and the entry document is the only object whose key stays stable. Hashed assets can be cached for a year because their name changes when their bytes change, and a release only has to invalidate the entry document.

Encrypt with SSE-S3 and record the reason. A customer-managed key would add a key policy, decrypt grants and per-request cost, and this site has no per-tenant or audit requirement that justifies them. If that requirement appears, the key becomes its own deliverable with its own owner.

Versioning is off, and the release record replaces it. A versioned bucket is never empty while delete markers remain, which turns a one-line destroy into a cleanup project. Keep the previous site archive beside the release record instead, and treat rollback as another upload.

The distribution is a short, explicit configuration. A default root object, GET and HEAD only, compression on, one managed cache policy and a price class that matches the audience. Every extra behaviour is another acceptance path, so the second behaviour should arrive with a requirement rather than with enthusiasm.

Custom error responses are part of the delivery, not a polish step. The origin returns an access error for a missing key, and the distribution turns both that error and a plain 404 into the site's error document with a 404 status. Without the mapping a typo looks like an outage, which trains readers to distrust the site.

The certificate lives in one region regardless of the bucket. CloudFront accepts a certificate only from us-east-1, so the AWS provider needs an alias fixed to that region. The validation records still belong in the same Cloudflare zone.

Order is certificate, distribution, record. Validation is a gate that must complete before the distribution can claim the hostname, and the DNS record must not exist before the distribution does. Terraform encodes that order through references rather than through a runbook.

Tags carry the ownership a name cannot. Project, environment, owner and expiry date belong on every taggable resource, and the expiry date is what makes a forgotten lab visible to a human. Cost allocation reads the same tags, which is how D5 stops being a separate spreadsheet.

ResourcePurposeDestroy risk
aws_s3_bucketorigin containerrefused while objects remain
aws_s3_bucket_public_access_blockfour exposure flagsnone on its own
aws_s3_bucket_ownership_controlsdisable ACLsnone on its own
aws_s3_bucket_server_side_encryption_configurationSSE-S3none on its own
aws_s3_bucket_policyOAC and TLS denymust go with the distribution
aws_cloudfront_origin_access_controlrequest signingdistribution breaks without it
aws_cloudfront_distributionTLS and cachemust be disabled before delete
aws_acm_certificate and validationserved certificatedistribution must go first
cloudflare_dns_record for the sitehostnametraffic stops within the TTL
cloudflare_dns_record for validationrenewalrenewal fails without it
Define Project-Owned DNS, Storage and Access Resources
%%{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','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    Z["Zone id
input, never a resource"] --> V["Certificate in us-east-1
DNS validation method"] V --> VR["Validation CNAME
grey, kept for renewal"] VR --> CV{"Certificate issued?"} CV -->|"no, record proxied"| F1["Pending forever
no distribution"] CV -->|"yes"| OAC["Origin access control
sign every request"] B["Bucket
private and encrypted"] --> PAB["Public access block
four flags on"] PAB --> POL["Bucket policy
service principal + source ARN"] OAC --> POL POL --> D{"Distribution created?"} D -->|"certificate in another region"| F2["Rejected by the API"] D -->|"yes"| R["Site CNAME
grey, short TTL"] POL -->|"wildcard principal"| F3["Public bucket
direct URL returns bytes"] R --> S["Endpoint serves
over HTTPS"] 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 Z,V,VR,OAC,B,POL primary; class PAB,R secondary; class CV,D ok; class S ok; class F1,F2,F3 danger;

The failure branches explain the order. Figure 3 is the sequence, and every red branch is a failure you can name before it happens. A proxied validation record leaves the certificate pending, a certificate from the wrong region is refused by the distribution, and a policy without the source condition returns an access error on every request the edge makes. Each branch is a different owner's mistake.

Separate Provider Credentials and Backend Access

Three identities, not two. A plan identity reads, an apply identity writes, and a release identity only puts objects under one prefix. Collapsing them is how a content deploy acquires the ability to delete a distribution.

Credentials arrive from the environment. Provider configuration reads the AWS session and the Cloudflare token from values injected into the runner's environment. Do not declare them as inputs that a tfvars file can supply, and never commit a file that contains them.

A saved plan is the only thing approval can attach to. The plan job writes an artifact, records its digest, and the apply job runs that exact file after checking the digest. A re-plan after approval is a new change, even when the diff looks identical, because the second plan was produced from a state nobody reviewed.

The token never becomes a Terraform variable. A sensitive variable still appears in a saved plan, and plan artifacts travel through storage and tickets. Reading the value from the environment keeps it out of both, and it also keeps the value out of every crash dump and debug log on the runner.

The Cloudflare token is zone-scoped and DNS-only. Two permission groups are enough: DNS edit for the two records, and zone read for the identifiers. The token names one zone, carries an expiry date, and is reviewed in the same pull request as the root it serves.

The AWS role is ARN- and region-scoped. Each statement names the bucket, the distribution, the origin access control or the certificate, and nothing else. A wildcard on CloudFront actions is the most common shortcut and the easiest one to justify badly.

IdentityTalks toAllowedLifetimeWhere it lives
PlanAWSread resources, write the lock objectone hourOIDC session
ApplyAWSbucket, OAC, distribution, certificateone hourOIDC session
ReleaseAWSput objects under the release prefix, create invalidationsfifteen minutespipeline OIDC
DNSCloudflareDNS edit and zone read, one zoneexpiry daterunner secret

Backend access is its own permission set. State lives under a project prefix in a versioned bucket, and locking uses a lock object beside it rather than a separate database. The plan identity may write that one object and nothing else in the state bucket.

The backend is bootstrapped before this root exists. The state bucket, its versioning and its access policy cannot be created by the configuration that stores its state in them. That bootstrap is a separate, reviewed change with a different owner, and the capstone consumes it as an input rather than rebuilding it.

The release identity is deliberately weaker. It writes under the release prefix and requests an invalidation, and it cannot read state, change the distribution or touch DNS. A rollback is another upload by the same identity, not an infrastructure change with an unreviewed diff.

Rotation is a calendar entry, not a hope. The token has an expiry date, the role session is measured in minutes, and the certificate renews itself only while its validation record exists. Put all three dates in D5, because a credential that expires silently is an outage with a scheduled cause.

Nothing crosses the boundary. The AWS session has no Cloudflare permission, the token has no AWS permission, and the release identity has neither. Three independent refusals are easier to prove than one carefully worded policy.

Figure 4 draws the lanes, and the barrier is the point. Each identity can reach exactly one API, and the state prefix is a fourth boundary that only two of them touch.

Four identities, two provider lanes and one state prefix The apply role and the release identity work in the AWS lane, the DNS token works in the Cloudflare lane, and no credential crosses between them. All four are separated from the state prefix, which the release identity cannot reach. Credentials by lane, not by convenience Each identity can reach one API and one scope. The state prefix is a fourth boundary. AWS lane Apply role OIDC, one hour one region, named ARNs Release identity put objects, invalidate no infrastructure Resources bucket · OAC · distribution · certificate in us-east-1 State access: read and lock one prefix. No Cloudflare permission, no second region. Cloudflare lane API token DNS edit and zone read one zone, expiry date set Resources site CNAME and validation CNAME No AWS permission, no second zone. No permission to delete the zone. no credential crosses Terraform state: one prefix, one lock object Identifiers and policy only — no object bytes, no token, no private key. The plan identity writes the lock; the release identity cannot reach the bucket.

A credential that can reach a second zone is a finding. It turns a misplaced resource into a cross-customer incident and makes the naming convention decorative. The blast radius of this capstone is exactly the token's zone list and the role's ARN list.

Plan the Delivery Path and Verify the Endpoint

Verification follows the request, not the resource list. A plan proves intent; a request proves behaviour. Run the checks in the order a browser meets them, and record each result separately so a failure points at one layer.

Preflight reads the plan for replacement, not for creation. A new bucket or distribution is expected on the first run; the same word on the second run means an argument changed that the resource cannot update in place. That single word is worth more review time than the whole additions list.

DNS comes first, at two resolvers. Ask the zone's authoritative server and a public recursive resolver for the hostname. They must agree, the record must be grey, and the answer must be the distribution's name rather than an edge address.

Negative answers are cached too. A name queried before its record existed can stay absent for the negative TTL, which makes a correct record look broken for minutes. Query after the apply, and record the time so a later reader can tell a cache from a mistake.

TLS is the second check, and it has three facts. The served chain must come from a public issuer, cover the hostname, and negotiate at least TLS 1.2. A valid certificate for the wrong name is the most common near miss, because the handshake succeeds while the site is still broken.

Verify from a network that did not build the site. A request from inside the same account, VPC or resolver proves the path you already control, not the path a visitor takes. Use an outside resolver and an outside client, and say which network produced each result.

Origin access is the third check, and it must fail. Request an object's REST URL directly and expect an access error rather than bytes. A successful response here means the bucket policy, the public access block or the origin access control attachment is wrong, and the site is public no matter what the edge reports.

Cache is the fourth check, and the header is the evidence. Request the same asset twice and read the cache result; a miss followed by a hit is the proof. A hit on the first request means something else answered it, and a miss on the second means the behaviour is not caching at all.

The cache key decides what a hit means. Query strings, the encoding header and cookies can all change the key, so the two requests must be identical in every respect except time. A hit on a request that should have reached the origin is a correctness bug, not a performance win.

The not-found path is a separate behaviour. With OAC and no list permission, S3 answers a missing key with an access error, so the distribution maps both 403 and 404 to the error document with a 404 status. Verify the mapped status rather than the origin's first response.

Wait for the distribution before judging it. A newly created distribution reports a deployment in progress, and requests during that window prove nothing about the configuration. Wait for the deployed status, then run the checks and timestamp every result.

Record the resolver, the time and the result. A log line that says "works" cannot be reviewed; a log line with the resolver address, the observed certificate and the time can be compared across runs. That comparison is what closes D4.

Invalidation is a release step, not a repair. The release writes its objects, invalidates the entry document, and waits for the invalidation to complete before it reports success. A wildcard invalidation used as a habit costs money and hides the day the entry document stopped being the only mutable key.

CheckWhat it provesPass signalOwner of a failure
DNSdelegation and the recordauthoritative and recursive answers agree, record is greyCloudflare
TLSchain, name and protocolpublic issuer, SAN match, TLS 1.2 or highercertificate or distribution
Originthe bucket is not publicaccess denied on the direct URLbucket policy or OAC
Cachethe edge is the cachemiss then hit on the same keycache behaviour
Not foundthe error path is mapped404 body with the mapped statuscustom error responses
No changeTerraform agrees with realitydetailed exit code zeroconfiguration or drift

A green apply proves none of the six. The apply proves that the API accepted the request, which is the weakest claim in the project. The capstone is accepted on the table above, not on the apply output.

Review Cost, State and Recovery Evidence

Cost is small, but it is not the guardrail. A forgotten distribution with no traffic bills almost nothing, so an idle project will not announce itself on an invoice. The guardrail is a tag, an expiry date and a review, not the monthly total.

ItemBilling dimensionAllowance to checkWhat to watch
S3 storageGB-monthnew-account allowance, time-limitedold release prefixes
S3 requestsper thousandnew-account allowance, time-limitedcache hit ratio
CloudFront transferGB outstanding monthly allowancethe only bill that scales with readers
CloudFront requestsper ten thousandstanding monthly allowanceassets per page
Invalidationsper path after the included pathsincluded paths per monthrepeated wildcard invalidation
Public certificateno chargenot applicablerenewal depends on the record
Cloudflare DNSno charge on the free plannot applicablenone for two records

Confirm the current published allowance rather than trusting a number in a blog post. Allowances change, and the S3 free tier is time-limited for new accounts while the CloudFront allowance is standing. Write the checked date beside the figure in D5.

The most likely failure is a hand edit, so give each one a signal. A dashboard change does not announce itself, but every one of them leaves a different trace that a reviewer can follow.

FailureFirst signalRepair owner
One object deleted by handa single 403 while the rest of the site worksrelease identity re-uploads
Site record edited in the dashboardresolver answer differs from the configurationDNS owner, then a plan
Validation record removedrenewal warning months laterDNS owner restores the record
Distribution edited by handa diff on the next no-change runapply identity reverts it
Stale lock after a crashed runplan blocks on the lock objectnamed operator clears it and records why

State is recoverable because the bucket keeps versions. A bad apply is repaired by restoring the previous state object, not by editing JSON by hand, and the restore itself is a change with a timestamp. Clearing a stale lock is a separate decision from restoring state, and both belong in the incident note.

State holds identifiers, not content. Expect the bucket name, the distribution identifier, the certificate reference and the record identifiers, and expect no object bytes, token or private key. Read the state listing as an inventory of claims, not as an inventory of the account.

Three rehearsals make recovery evidence. Restore an object from the release archive and compare checksums, change the record and watch the old answer expire, and confirm the validation record still resolves. Each rehearsal ends with the original state restored and recorded with a timestamp.

Certificate renewal depends on a record people delete. ACM renews a DNS-validated certificate by re-checking the same CNAME. Removing it after issuance looks tidy and turns the next renewal into a support incident, which is why it is called out in the cleanup record as well as in the resource map.

The destroy plan is a reviewed artifact. Generate it, save it, and read it for what is absent: the zone, the apex, mail and the DNSSEC signing must not appear. The same read catches a resource that drifted into this root by accident.

Cleanup runs in dependency order. Delete objects, disable the distribution, wait for the deployed status, delete the distribution, remove the records, then the bucket and the certificate. Deleting the bucket first leaves an edge pointing at nothing, and deleting the zone takes unrelated services with it.

Figure 5 is the scope proof, and the right column is what a reviewer reads first. The left column is short and disposable; the right column is the reason the destroy plan needs an owner rather than a script.

Destroy scope: what this root owns and what it must never touch A reviewed destroy plan contains the site record, the validation record, the distribution, the origin access control, the bucket policy, the bucket and the certificate. The zone object, apex records, mail records and DNSSEC signing are absent from the plan and survive. A destroy plan is a scope proof Read the plan for what it removes and for what it leaves alone. terraform plan -destroy, saved and reviewed before it runs In this root, planned for destroy site CNAME and validation CNAME distribution and origin access control bucket policy, bucket and its settings certificate and its validation Every name carries the project prefix. Nothing else may be addressed by this state. Seven to ten resources, all disposable. Outside this root, absent from the plan the zone object and its delegation apex address records mail MX and verification TXT records DNSSEC signing and the DS chain every other subdomain in the zone Their absence is the evidence. Presence in the plan means the scope leaked. Destroy order objects → disable distribution → wait for deployed → delete distribution → remove records → delete bucket → delete certificate A bucket with objects and a distribution that is still enabled both refuse deletion, in that order. Deleting the zone or the signing resource would take mail, the apex and every other subdomain with it.
Review Cost, State and Recovery Evidence
%%{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','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    P["Saved plan
digest recorded"] --> A{"Apply clean?"} A -->|"no"| F1["Fix and re-plan
new digest"] A -->|"yes"| V["DNS, TLS, origin, cache"] V --> Q{"All four pass?"} Q -->|"no"| F2["One layer fixes
re-run that check only"] Q -->|"yes"| N{"Plan exit code"} N -->|"two"| F4["Drift remains"] N -->|"one"| F5["The check itself failed"] N -->|"zero"| E["Evidence pack
and cost record"] E --> DP{"Destroy plan reviewed?"} DP -->|"no"| F3["No cleanup"] DP -->|"yes"| C["Destroy in order
objects to certificate"] C --> OK["Accepted
zone still present
state empty"] 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,V,E primary; class A,Q,DP,N ok; class C secondary; class OK ok; class F1,F2,F3,F4,F5 danger;

Figure 6 turns the same sequence into gates. A missing gate is not a shortcut, it is an unreviewed change with a green checkmark beside it.

A destroy that fails on a non-empty bucket is the guardrail working. The refusal names the resource that still holds data, which is more useful than a silent success. Empty it deliberately, then run the same plan again and record both attempts.

The post-destroy proof is a query set and one listing. Ask the hostname at a public resolver and expect no answer, confirm the zone still answers for its apex and mail names, and confirm the state lists no resources. Those results are the difference between "I ran destroy" and "the project is gone and the platform is intact".

Submit the Architecture, Evidence and Cleanup Record

Submission is a folder, not a paragraph. The reviewer wants the decision record, the ownership map, the verification log, the cost and state note, and the cleanup record, each named and dated. A dashboard screenshot is an illustration; a saved plan and a query result are evidence.

Repeatability is a second run, not a re-read of the first. Apply the same configuration from empty state with a new bucket suffix, and confirm the second run needs no manual step the first did not. Record the differences, because a suffix is legitimate and a console click is not.

The no-change plan closes the loop before cleanup. Run it after the last apply and before the destroy, and confirm zero. Exit code two means something drifted back, and exit code one means the check itself failed; after the destroy, the equivalent proof is an empty state listing rather than a plan.

State the limits of what you proved. One hostname, one region, one cache, no proxy and no WAF is a complete and honest scope. A capstone is stronger when its boundary is explicit than when its claims are broad.

Capstone

Static delivery acceptance review

Status: design-only. No AWS or Cloudflare credential was used to produce this capstone, and none of the steps below were executed here. Versions: Terraform CLI 1.17.1, hashicorp/aws 6.72.0, cloudflare/cloudflare 5.28.1, checked 6 November 2026.

Prerequisites. One zone you can add records to but must not delete, one AWS account and region, a bucket suffix that is unique, a certificate request in us-east-1, a scoped Cloudflare token with DNS edit on one zone, and an AWS role scoped to the named ARNs. Confirm the cost ceiling before the first apply.

Deliverables to attach. D1 decision record, D2 ownership map, D3 working endpoint, D4 verification log, D5 cost and state note, D6 cleanup record. The review is not complete until every row of the acceptance table has an artifact behind it.

StageActionPass condition
PreflightSave the apply plan and record the toolchain versionsNo unexpected replace or destroy, digest recorded
IssueApply, then wait for the distributionCertificate issued and status deployed
ResolveQuery the authoritative server and a public resolverSame grey CNAME answer at both
ConnectInspect the served chain for the hostnamePublic issuer, SAN match, TLS 1.2 or higher
RefuseRequest the REST URL for one object directlyAccess denied, zero bytes returned
CacheRequest one asset twiceMiss, then hit on the second request
MissRequest a key that does not exist404 with the mapped error document
ReconcilePlan with detailed exit codesExit code zero
CleanApply the reviewed destroy planZone, apex and mail still resolve

Expected observation. The hostname resolves to the distribution through a grey CNAME, the certificate is public and current, the direct bucket URL is refused, and the second asset request reports a hit. The plan before cleanup exits zero, and after cleanup the endpoint is gone, the state is empty and the zone still answers.

Failure checks. A certificate that stays pending usually has a proxied validation record or a record in the wrong zone. A 200 from the direct URL means the public access block or the policy condition is wrong. A permanent miss means the cache behaviour is not attached to the default behaviour. A destroy that removes the records but not the distribution means it was still enabled.

Cost dimensions. Storage and requests for a fixture site are cents. The transfer bill follows readers, not the configuration, and invalidations beyond the included paths are billed per path. The certificate and the two DNS records add nothing on their own, which is why the tag and the expiry date do the guarding.

Cleanup. Empty the release prefix and delete its versions if versioning was ever enabled, disable the distribution and wait for the deployed status, delete it, remove both records, then delete the bucket and the certificate. Leave the zone, the apex and the DNSSEC signing exactly as they were, and prove it with the resolver queries and the empty state.