Pulumi Zone Worker DNS Deployment and ESC Secret Lifecycle
How to add a site, deploy Workers, manage stacks, and store Cloudflare credentials with Pulumi and ESC, per Cloudflare’s IaC tutorials.
This page summarises Cloudflare’s Pulumi documentation: using Pulumi infrastructure as code to onboard a domain as a Zone, publish DNS records, deploy Workers with routes, and manage secrets through Pulumi ESC. The material comes mainly from Cloudflare’s step-by-step tutorials on adding a site, deploying a Worker, installing the CLI, managing secrets, and an advanced Pulumi plus Wrangler pattern.
Pulumi on Cloudflare: what you are automating
Section titled “Pulumi on Cloudflare: what you are automating”Pulumi lets you declare Cloudflare resources in a general-purpose language (TypeScript, JavaScript, Python, Go, .NET, Java, or YAML) instead of clicking through the dashboard. Cloudflare describes the goal of the “add site” path as learning the resource management lifecycle while creating a Zone and DNS record—the same steps as the interactive add-site flow, but expressed as code.
In this tutorial, you will follow step-by-step instructions to bring an existing site to Cloudflare using Pulumi infrastructure as code (IaC) to familiarize yourself with the resource management lifecycle. In particular, you will create a Zone and a DNS record to resolve your newly added site.
— Cloudflare, Add a site
For Workers, the parallel tutorial creates a Workers Script, a Workers Route, and a DNS Record so the app is reachable on your domain before you tear everything down.
In this tutorial, you will follow step-by-step instructions to deploy a Hello World application using Cloudflare Workers and Pulumi infrastructure as code (IaC) to familiarize yourself with the resource management lifecycle. In particular, you will create a Worker, a Route, and a DNS Record to access the application before cleaning up all the resources.
— Cloudflare, Deploy a Worker
Cloudflare’s tutorial index lists three learning tracks: add a site (Zone and DNS), manage secrets (ESC with Wrangler), and deploy a Worker (script, route, DNS).
Before you begin: accounts, CLI, and API tokens
Section titled “Before you begin: accounts, CLI, and API tokens”Install and verify Pulumi
Section titled “Install and verify Pulumi”Install the CLI for your OS (Homebrew on Mac, install script on Linux, MSI on Windows), then confirm it works:
pulumi versionSee Get started (installing Pulumi) for platform commands. Pulumi is free and open source; you can pair it with hosted Pulumi Cloud for state and secrets.
API token permissions differ by tutorial
Section titled “API token permissions differ by tutorial”| Tutorial | Token needs (from Cloudflare docs) |
|---|---|
| Add a site | Zone-Zone-Edit, Zone-DNS-Edit, include all zones from your account |
| Deploy a Worker | Account-Workers Scripts-Edit, Zone-Workers Route-Edit, Zone-DNS-Edit |
You also need a Pulumi Cloud account (individual free tier), the Pulumi CLI, a chosen language runtime, and a domain. The Worker tutorial assumes the domain is already on Cloudflare—Cloudflare tells you to complete Add a site first.
Store settings in Pulumi ESC
Section titled “Store settings in Pulumi ESC”Tutorials store accountId, cloudflare:apiToken, and domain in a Pulumi ESC Environment (YAML config and secrets in Pulumi Cloud), for example:
E=cloudflare/my-dev-envpulumi config env init --env $E --yespulumi env set $E --plaintext pulumiConfig.accountId abc123pulumi env set $E --secret pulumiConfig.cloudflare:apiToken API_TOKENpulumi env set $E --plaintext pulumiConfig.domain example.comThe Manage secrets with Pulumi ESC tutorial extends this pattern for Wrangler, CLOUDFLARE_API_TOKEN, Worker secrets, and .dev.vars.
— Cloudflare, Get started
Projects, stacks, and the deploy lifecycle
Section titled “Projects, stacks, and the deploy lifecycle”What is a Pulumi project and stack?
Section titled “What is a Pulumi project and stack?”A Pulumi project is a folder with a required Pulumi.yaml that describes infrastructure. A Pulumi program is the code that defines resources. A stack is one instance of that program (for example dev for development).
Typical first-time flow from the tutorials:
- Log in:
pulumi login(browser or access token). - Create a program:
pulumi new typescript --name addsite-cloudflare --yes(or another supported language). - Create the stack:
pulumi up --yes(empty stack until resources are defined). - Install
@pulumi/cloudflare(or the language equivalent). - Define resources, then
pulumi up --yesagain to apply. - Read outputs:
pulumi stack output. - Clean up:
pulumi destroy --yes, thenpulumi stack rm dev.
Both Add a site and Deploy a Worker note that resources used qualify for free tiers on Pulumi Cloud and Cloudflare.
Add a site: Zone resource and DNS record in code
Section titled “Add a site: Zone resource and DNS record in code”Zone: domain as a Cloudflare Zone
Section titled “Zone: domain as a Cloudflare Zone”In Cloudflare, a domain or site is a Zone. In Pulumi, cloudflare.Zone creates it. The tutorial uses plan: "free" and jumpStart: true, and exports zoneId, nameservers, and status for later steps.
Conceptually (TypeScript):
const zone = new cloudflare.Zone("my-zone", { zone: domain, accountId: accountId, plan: "free", jumpStart: true,});After deploy, Cloudflare states that once the domain is successfully registered, status becomes active—check with pulumi stack output.
DNS record: proxied A record on the zone
Section titled “DNS record: proxied A record on the zone”The add-site tutorial adds a cloudflare.Record tied to zone.id, with type: "A", placeholder content 192.0.2.1, and proxied: true so traffic goes through Cloudflare’s proxy. Full examples for every language are in Add a site.
Deploy a Worker: script, route, and DNS together
Section titled “Deploy a Worker: script, route, and DNS together”WorkersScript: inline Hello World
Section titled “WorkersScript: inline Hello World”The Worker tutorial deploys script content directly in IaC—a cloudflare.WorkersScript with module: true for an ES module fetch handler returning plain text. Permissions and packaging limits follow Cloudflare’s Workers product rules; the tutorial only demonstrates the minimal script resource.
WorkersRoute: bind a hostname pattern to the script
Section titled “WorkersRoute: bind a hostname pattern to the script”A Workers Route needs the zone ID. Existing zones use a lookup (getZone / get_zone) rather than creating a new Zone. The pattern in the tutorial is hello-world. plus your domain, with scriptName set to the worker’s name.
DNS record for the route hostname
Section titled “DNS record for the route hostname”The DNS record’s name matches route.pattern. With proxied: true, the stack exports a URL such as https://${record.hostname}. Test with:
curl $(pulumi stack output url)Cloudflare notes you may need http instead of https depending on domain settings. The complete single-file solutions per language are in Deploy a Worker.
When to use Pulumi only, Wrangler, or both
Section titled “When to use Pulumi only, Wrangler, or both”The Pulumi and Wrangler example uses two strategies:
This example creates a zone and other resources using two different strategies:
Use Pulumi for some resources supported by the Cloudflare Pulumi provider. Use Wrangler to create other types of resources.
— Cloudflare, Create different resources using Pulumi and Wrangler
Pulumi in that sample manages Zone, Queues, D1, Zero Trust Access objects, and similar registry resources. Wrangler runs via command.local.Command—for example npx wrangler d1 migrations apply … --remote and npx wrangler deploy—with file-hash triggers so changes redeploy. Resources not yet in the official provider (the sample builds a dynamic provider for Vectorize) can call the Cloudflare API directly; the sample notes Vectorize does not allow updates after creation.
Exports such as pulumi stack output myServiceTokenClientSecret --show-secrets are intended for CI pipelines consuming stack outputs.
Pulumi ESC and Wrangler: credentials without shell exports
Section titled “Pulumi ESC and Wrangler: credentials without shell exports”Manage secrets with Pulumi ESC teaches centralized secrets: an Environment is YAML configuration and secrets in Pulumi Cloud, reachable from the ESC CLI (esc login) and from tooling like Wrangler. The stated goals include managing CLOUDFLARE_API_TOKEN, passing ESC-stored secrets to Workers, and loading .dev.vars programmatically—so local development does not depend on long-lived tokens in your shell profile.
Clean up and dependency order
Section titled “Clean up and dependency order”Tutorials end with pulumi destroy (or pulumi destroy --yes) and pulumi stack rm dev. For composite apps, Cloudflare’s realtime example reminds you to end active rooms and wait for cleanup before removing backends, run npx wrangler delete from the example directory, remove Access applications separately, delete .dev.vars when credentials are unused, and only delete a dedicated SFU app after dependents stop—see Custom video room for that teardown pattern when Workers and Access were created outside a single Pulumi destroy.
Common mistakes
Section titled “Common mistakes”- Wrong API token scope — Zone-only tokens cannot deploy Workers; Worker tutorials need Workers Script and Route permissions (token lists above).
- Deploying a Worker before the zone exists — Deploy a Worker requires a Cloudflare-managed domain from Add a site.
- Editing resources outside Pulumi — Dashboard changes to Pulumi-managed Zones, records, or routes cause drift; Cloudflare recommends managing those resources only through Pulumi (installing note).
- Mixing Wrangler and Pulumi without orchestration — Running
wrangler deploymanually while a stack also runscommand.local.Commandcan fight over the same Worker unless hashes and dependencies match the dynamic provider example. - Expecting Vectorize updates via IaC — The sample dynamic resource documents that Vectorize does not allow changes after creation.
How to check this on your site
Section titled “How to check this on your site”- Run
pulumi versionand confirm the CLI matches Get started. - After
pulumi up, runpulumi stack outputand confirm Zonestatusis active for add-site flows (Add a site). - For Workers,
curl $(pulumi stack output url)and confirm the Hello World response (Deploy a Worker). - In the Cloudflare dashboard, verify the Zone, DNS records, Worker script, and routes match what your stack defines (D1 migration checks in the hybrid example use
SELECT * FROM d1_migrationson the D1 console, per Pulumi and Wrangler). - You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will correct or clarify it.