How It Works
flowchart TD
A["wrangler-deploy.config.ts"] -->|declares resources, bindings, stages| B["wd apply --stage <name>"]
B -->|provisions resources via wrangler CLI| C["State (local or KV)"]
C -->|tracks what was created, with IDs| D["Rendered wrangler configs"]
D -->|real IDs, stage-suffixed names| E["wd deploy --stage <name>"]
E -->|wrangler deploy with rendered configs| F["wd destroy --stage <name>"]
F -->|reverse-order teardown| G["Clean slate"]
What happens at each step
Section titled “What happens at each step”wd apply
Section titled “wd apply”- Reads
wrangler-deploy.config.ts - Resolves state backend (local filesystem or remote KV)
- For each resource, calls
wrangler kv namespace create,wrangler d1 create,wrangler queues create, etc. - Writes state after each resource (resumable on failure)
- Generates a rendered
wrangler.rendered.jsoncper worker with real IDs and stage-suffixed names - Idempotent: existing resources are adopted, not recreated
wd deploy
Section titled “wd deploy”- Reads state to find rendered configs
- Validates all declared secrets are set (blocks if missing)
- Resolves deploy order from service bindings (or explicit
deployOrder) - For each worker, calls
wrangler deploy -c <rendered-config> - Runs from the worker directory so relative paths resolve correctly
- Optional
--verifyruns post-deploy coherence checks
wd dev
Section titled “wd dev”- Uses the checked-in
wrangler.jsoncfiles by default - When you pass
--stage <name>, renders stage-specific configs from the applied stage state - Uses those rendered configs to start local workers or a shared session, so local bindings match deploy-time state
- Keeps the original
wrangler.jsoncfiles untouched
wd destroy
Section titled “wd destroy”- Checks stage protection rules (refuses without
--forcefor protected stages) - Removes queue consumers first (Cloudflare requires this before worker deletion)
- Deletes workers in reverse deploy order
- Deletes resources (queues, KV, D1, Hyperdrive, R2)
- Handles “not found” gracefully (resources may already be gone)
- Cleans up state
State management
Section titled “State management”By default, state lives locally in .wrangler-deploy/<stage>/state.json. For teams and CI, use remote KV state:
state: { backend: "kv", namespaceId: "your-kv-namespace-id",}All commands (apply, deploy, destroy, verify, secrets, gc, status) go through the same StateProvider interface. Switching backends is a config change.
Authentication
Section titled “Authentication”wrangler-deploy uses wrangler for all Cloudflare operations:
- Local:
wrangler login(OAuth), account ID auto-resolved fromwrangler whoami - CI/CD:
CLOUDFLARE_API_TOKEN+CLOUDFLARE_ACCOUNT_ID
No separate authentication needed. If wrangler works, wrangler-deploy works.
Trust boundary
Section titled “Trust boundary”wrangler.jsonc remains the primary authoring format. wrangler-deploy adds orchestration around it instead of replacing it. Rendered configs under .wrangler-deploy are generated artifacts for deploy and stage-aware local dev, not files you are meant to edit by hand.