Back to Terraform

Static Applications: Pages, Worker Assets and Custom Domains

November 6, 2026 Wasil Zafar 18 min read

Manage hosting configuration while separating builds, content deployment and domain activation

Table of Contents

  1. Compare Pages and Worker Static Assets by Lifecycle
  2. Own Hosting Configuration and Build Settings Explicitly
  3. Keep Build Output and Content Synchronization Out of Configuration Drift
  4. Coordinate Custom Domains, DNS and Certificate Readiness
  5. Verify a Release and Keep the Previous Artifact Recoverable

Compare Pages and Worker Static Assets by Lifecycle

Both products serve files from the edge, but they disagree about what a release is. A Pages release is a deployment object with its own immutable URL. A Worker release is a version that carries the script, the asset manifest and the routing configuration together. That difference decides what can be previewed, promoted and rolled back.

Pages grew around a build service. A Git-connected project lets Cloudflare run the build, while a direct-upload project accepts a directory that was built elsewhere. Worker static assets assume the second model: CI produces the output and uploads it with the Worker.

A Pages deployment is immutable and addressable. Every successful build gets a hash-based URL that stays reachable, plus a branch alias that moves to the newest commit on that branch. Production is the alias attached to the custom domain. Only successful production deployments are valid rollback targets; a preview deployment is not.

A Worker version is the comparable unit. It holds the script, the assets and their configuration, and a deployment decides which version serves traffic. Preview is a version URL, and rollback creates a new deployment from an older version.

Figure 1 traces both release paths from the same commit and marks where they diverge.

Compare Pages and Worker Static Assets by Lifecycle
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    S["Commit
+ lockfile"] --> B{"Build
owner?"} S -.->|"no lockfile"| X["No reproducible
identity"] B -->|"Cloudflare"| PB["Pages build
command · output"] B -->|"CI"| AB["CI output
+ hash"] PB --> PD["Deployment
hash URL"] AB --> PD AB --> WV["Worker
version"] PD --> BA["Branch alias"] PD --> PA["Prod alias
custom domain"] PD --> RB["Rollback
target"] WV --> VU["Version URL
preview"] WV --> WD["Worker
deployment"] WD --> WR["Rollback
new deployment"] VU -.->|"not eligible"| RB classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class S,B primary; class PB,PD,BA,PA secondary; class AB,WV,VU,WD ok; class RB,WR warn; class X danger;

Figure 2 separates the objects Terraform writes from the ones it can only observe.

What Terraform writes, what the platform owns and what the edge serves Terraform writes the Pages project, the Worker script and the domain objects. The platform creates deployments, versions and certificates. The edge serves a response that Terraform never stores, and release identity is proved by a commit plus a manifest hash. Who writes what in a static hosting stack Terraform configuration Pages project build + source config Worker script assets + routing config Domain objects domain + DNS record Build output: not in state Platform objects Deployment hash URL + alias Worker version script + manifest Certificate issued asynchronously Computed attributes Edge and evidence Custom hostname TLS + routing Served response the artifact under test Release identity commit + manifest hash Not chosen by Terraform waits for Outside Terraform state The build output, the choice of alias, the certificate issuance and the bytes the edge actually serves.

Read the lifecycle as a table, not a product slogan. The build, preview and rollback columns decide who needs CI, how review works and what an incident costs. A team already on Workers gains little from a second project object; a team that relies on previews gains from Pages.

StagePagesWorker static assets
BuildCloudflare build image for a Git project, or a prebuilt directory for direct uploadAlways outside Cloudflare; CI or a local build produces the directory
Release objectDeployment with an immutable hash URL and branch aliasesVersion containing script, assets and asset configuration
PreviewHash URL per commit plus a moving branch aliasVersion URL, addressable until the version is deleted
Production switchThe production alias and attached custom domainsA deployment that assigns a version to routes and domains
RollbackPrevious successful production deployment; previews excludedNew deployment of an older version
Terraform surfaceProject, build config and domains; no deployment resourceScript and assets, or a data source plus domain resources

Terraform can create a Pages project but not a Pages deployment, so content belongs to a build pipeline. It can upload Worker assets from a directory, so one tool can own configuration and artifact. That asymmetry explains most of the drift below.

Neither product is a universal replacement. Cloudflare now points new projects at Workers, while Pages continues to serve existing ones. The migration decision is about build ownership, preview workflow and rollback evidence.

Own Hosting Configuration and Build Settings Explicitly

Terraform owns the hosting container, not the release. The container is the project or script, its build contract, the domain objects and the DNS that attaches them. A release is whatever the build pipeline or the upload step produces inside that container.

Verify the pinned schema before reusing an example. The Pages domain resource takes the hostname as name, and Worker assets sit under an assets block on the script. A v4-era snippet fails at plan with an unsupported argument rather than a subtle misconfiguration. These examples use Terraform CLI 1.17.1 with cloudflare/cloudflare 5.28.1.

A Pages project needs very little. An account, a name and a production branch are required; the build, source and deployment blocks are optional and answer different questions. build_config describes how Cloudflare should build, while deployment_configs describes what the built application receives at runtime.

Build settings only apply when Cloudflare builds. With a Git source, the build image reads the command, root directory and output directory. With direct upload no build runs, so the same settings have nothing to act on and become documentation of an intention.

The source block is a creation-time decision. Adding a Git source connects a repository and enables push-driven builds; omitting it creates a direct-upload project. A Git project cannot later be converted to direct upload, so the choice belongs in the first pull request, not in a later cleanup.

Preview and production are configured separately. Compatibility date, bindings and environment variables exist in both deployment configurations, so a preview can point at a staging namespace without touching production. Copying production values into preview is a decision, not a default.

Asset routing is configuration; the files are content. On a Worker, the assets block owns html_handling, not_found_handling and worker-first paths. The directory field points at the bytes, and Terraform computes a manifest hash after the upload.

A completion token is not a credential to keep. The sensitive jwt value proves that an asset upload session finished; it is short-lived and belongs in the apply, not in a repository or a shared variable set.

Figure 3 follows the decision from source to hosting object and shows where a valid plan still produces the wrong lifecycle.

Own Hosting Configuration and Build Settings Explicitly
%%{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
    R["Repository"] --> Q{"Hosting
target?"} Q -->|"Pages + Git"| G["Git-connected
project"] Q -->|"Pages direct"| D["Direct-upload
project"] Q -->|"Worker"| A["Assets
directory"] G --> BC["build_config
command · root"] BC --> BD["Cloudflare build
new deployment"] D --> DL["CI upload
pages deploy"] BC -.->|"changed later"| NX["Next build only
not a rebuild"] D -.->|"build_config set"| IG["Nothing reads it"] G -.->|"convert later"| X1["Not supported
after creation"] BD --> DOM["pages_domain
name + status"] DL --> DOM A --> AM["Manifest hash
+ completion"] AM --> WV["Worker version"] A -.->|"absent at plan"| X2["Plan fails
before upload"] WV --> CD["custom_domain
DNS + certificate"] 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 R,Q,A primary; class G,D,BC,BD,DL,DOM secondary; class AM,WV,CD ok; class NX,IG warn; class X1,X2 danger;

Two settings deserve a second look before apply. The output directory must match what the framework writes, because a wrong destination deploys the wrong tree successfully. The production branch must match the branch that triggers production, or a merge builds a preview while the domain keeps the previous release.

Keep Build Output and Content Synchronization Out of Configuration Drift

Drift has two meanings here, and only one belongs to Terraform. Configuration drift is a resource that no longer matches its HCL. Content drift is a deployment or version Terraform never saw. A clean plan after a deploy is the expected result when the pipeline owns content.

Choose one content owner per hostname. Git build, CI upload or Terraform upload: pick one and make the other tools read-only on that path. Two writers do not merge; they take turns overwriting each other, and the winner is whichever ran last.

Pages makes the split natural. Terraform owns the project and the domain, while Git or CI owns the bytes. The project's deployment fields are computed, so a deploy changes them without changing configuration; planning again should still report no changes.

Read-only deployment fields are evidence, not inputs. The latest and canonical deployment objects move with every push, and the canonical trigger carries the commit hash. Exporting them into another stack creates a dependency on a value that changes for a reason unrelated to that stack.

Worker assets invert the ownership. With a directory configured, apply uploads whatever is present on disk, so Terraform owns the artifact as well as the configuration. A Wrangler deploy between applies is then reverted by the next apply, and a Terraform apply is overwritten by the next deploy.

If CI owns the Worker artifact, do not also manage the upload. Reference the script through a data source and let Terraform own the custom domain, DNS and bindings. The deploy job owns versions; Terraform owns the name and the route.

ignore_changes is a confession, not a fix. Hiding content or manifest attributes from the plan conceals a second writer and removes the only signal that would reveal it. Remove the competing writer or remove the resource from Terraform's ownership instead.

Reproducibility decides whether a hash can be an identity. Rebuild the same commit twice; if the asset manifest differs, the build is not deterministic and its hash cannot prove which source produced the release. Keep the artifact in CI storage and treat state as a reference, not a warehouse.

Coordinate Custom Domains, DNS and Certificate Readiness

A hostname is ready when DNS, domain status and certificate agree. Apply returns when the API accepts the objects, not when the edge can serve them. Activation is asynchronous, and a green apply followed by a TLS error is an ordering problem before it is a configuration error.

Pages makes DNS your job. The domain resource registers the hostname but does not create a record, so a proxied CNAME to the project's pages.dev name is part of the configuration. At the apex, Cloudflare flattens that CNAME, which is why the same pattern works for both shapes.

Workers makes DNS Cloudflare's job. A custom domain creates the record and the certificate on your behalf, so a hand-written record for the same hostname is a competing owner. Import or remove the old record before adding the domain.

Order the resources deliberately. For Pages, create the record, then the domain, then wait for active. For Workers, create the domain and verify TLS, because the resource exposes a certificate identifier rather than a readiness status.

CAA records can veto a certificate that DNS is ready for. If the zone publishes CAA records, they must allow the authorities Cloudflare uses, or issuance stays pending while every other check passes.

Status words describe different failures. Initializing and pending are progress; active is ready; blocked and error need a human; deactivated means the hostname was detached.

Preview hostnames are not production hostnames. Branch aliases move with every commit and cannot be rollback targets, so attaching a durable custom domain to one publishes unfinished content under a stable name.

Figure 4 places the apply boundary before activation and shows where a domain becomes blocked instead of active.

Domain activation continues after Terraform apply returns Terraform creates the DNS record and the domain object, then apply returns. Cloudflare validates the hostname asynchronously, issues the certificate and only then does the hostname serve traffic. A failed validation lands in blocked or error and needs a human. Ready is a state, not a successful apply 1 · DNS record CNAME to the project 2 · Domain object name + project 3 · Validation initializing → pending apply returns 4 · Certificate issued for the hostname 5 · Verify TLS, HTML, redirect 6 · Switch traffic after the old TTL Blocked or error validation needs a human fails Preview aliases stay on their own hostname They move per commit and are not valid rollback targets.

Cutover is a TTL problem before it is a Cloudflare problem. Lower the TTL a day ahead, attach the hostname, verify the certificate, then move traffic. Keep the old target until the old TTL has expired for resolvers and clients that cached it.

Verify a Release and Keep the Previous Artifact Recoverable

Verify the served response, not the plan. A release is correct when the custom hostname returns the expected HTML, a hashed asset returns with the cache policy its fingerprint calls for, redirects resolve in one hop, and the fallback matches the chosen mode.

Identity ties the bytes to a commit. On Pages, the canonical deployment carries the triggering commit; on a Worker, annotate the version with the commit and read the computed manifest hash. Record both next to the deployment or version identifier.

Rollback is a platform action, not a Terraform action. Pages rolls back to an earlier successful production deployment, while a Worker rollback creates a new deployment from an older version. Neither operation edits the project or script configuration.

Terraform will undo an out-of-band rollback if it owns the artifact. That is the ownership rule under pressure: either revert the commit and apply forward, or pause the pipeline and record the manual deployment. A rollback that the next plan erases is not a recovery plan.

Keep the previous artifact reachable. Pages keeps deployments addressable by hash and Workers keep versions addressable by identifier, but the build log and lockfile are what let you rebuild the same output. Retention is part of the release design, not cleanup.

Lab

Review a static hosting release

Status: design-only. No Cloudflare credential was used to produce this article, and these steps were not executed here. Versions: Terraform CLI 1.17.1, cloudflare/cloudflare 5.28.1, verified 6 November 2026.

Prerequisites. A zone you can delegate, one Pages project with a preview deployment, one Worker with an assets directory, a test hostname such as deploy.example.com, and an API token with Pages, Workers Scripts and DNS write access.

ObjectValue to useWhy it matters
Test hostnamedeploy.example.comexercises a subdomain before any apex cutover
Pages projectone Git-connected projectbuild, preview and rollback behaviour
Workerone script with an assets directorymanifest-based release identity
Build markera unique string in the HTMLproves which artifact answered
Asset headercache policy on a hashed filematches the fingerprint policy, not the HTML fallback
  1. Baseline. Request the production hostname and record status, the cf-ray value, a hash of the HTML body and the certificate subject.
  2. Identity. Read the canonical deployment commit or the Worker version annotation, plus the asset manifest hash. Write both into the release note before changing anything.
  3. Preview first. Request the preview URL and one hashed asset. Confirm both return 200, the asset has the expected content type and, on Pages, the preview carries a noindex header.
  4. Attach the hostname. For Pages, create the record and then the domain; for Workers, create the domain only. Poll status or perform a TLS handshake until the hostname answers with a valid certificate.
  5. Compare bytes. Fetch the HTML and one asset from the preview and from the custom hostname. They should be identical apart from absolute URLs that the build rewrites.
  6. Roll back one release. Select the previous successful production deployment on Pages, or roll back the Worker version. Confirm the old build marker returns, then restore the current release.
  7. Reconcile. Run a plan and expect no changes. If Terraform owns the Worker artifact, confirm the out-of-band rollback left a pending diff and resolve it before the next pipeline run.
  8. Clean up. Detach the test hostname, delete the temporary preview, remove the test record, and keep the build log and artifact for the release under review.

Expected observation. A sequence rather than a duration: apply returns, validation completes, the certificate covers the hostname, the custom hostname serves the same bytes as the preview of that commit, and a rollback changes the served marker.

Failure checks. A 404 on a hashed asset points at the output directory. HTML that loads while assets 404 points at a base path mismatch. A 522 points at a record that reaches pages.dev without the Pages domain association. A certificate warning points at a hostname that is not active. A redirect loop points at a redirect rule that conflicts with HTML handling. A missing rollback target means the release was only ever a preview.

Cleanup. Confirm the hostname, preview and test record are gone, and keep the artifact and build log.

References (verified 6 November 2026):

  • Pages overview: https://developers.cloudflare.com/pages/
  • Direct upload: https://developers.cloudflare.com/pages/get-started/direct-upload/
  • Pages custom domains: https://developers.cloudflare.com/pages/configuration/custom-domains/
  • Pages rollbacks: https://developers.cloudflare.com/pages/configuration/rollbacks/
  • Workers static assets: https://developers.cloudflare.com/workers/static-assets/
  • Workers custom domains: https://developers.cloudflare.com/workers/configuration/routing/custom-domains/
  • cloudflare_pages_project: https://registry.terraform.io/providers/cloudflare/cloudflare/5.28.1/docs/resources/pages_project
  • cloudflare_pages_domain: https://registry.terraform.io/providers/cloudflare/cloudflare/5.28.1/docs/resources/pages_domain
  • cloudflare_workers_script: https://registry.terraform.io/providers/cloudflare/cloudflare/5.28.1/docs/resources/workers_script

Next in the Series

In Cloudflare Access: Applications, Identity and Service Authentication, we'll explore Model Zero Trust access policies with explicit evaluation, credential and recovery boundaries.