UniverLab's Cloudflare account as code (Terraform, Cloudflare provider v5). Nothing in the account is created or changed by hand any more: a change is a pull request here.
Each folder under stacks/ is its own root module with its own state
(univerlab-tfstate R2 bucket, key stacks/<name>.tfstate), so a change plans
and applies only what it touches.
| Stack | What it holds |
|---|---|
dns |
univerlab.org DNS records and email routing rules |
storage |
R2 buckets and KV namespaces |
access |
Cloudflare Access applications and Turnstile widgets |
pages |
Pages projects univerlab and quorum: settings, bindings, plain variables |
workers |
Every Workers custom domain and route (get, install, graphs, announcements, remote). wrangler.toml files declare none |
atmosferas |
The atmosferas Pages project (personal project, kept apart) |
shared/ holds the provider and variables every stack links to.
Outside Terraform on purpose:
- Worker code and its bindings (
wrangler.tomlin each repo) are uploaded by that repo's deploy workflow with wrangler. Domains and routes are not in anywrangler.toml: they are here, so a deploy never fights Terraform. - Secrets never go in this repo. Worker secrets reach Workers through each
repo's deploy workflow (
wrangler secret). The few Pages secrets this repo manages (e.g.RESEND_API_KEY) come from GitHub secrets as sensitiveTF_VAR_*variables, so they are stored in the state bucket, which only the scoped R2 credentials can read. - The state bucket
univerlab-tfstateitself (bootstrap).
- Branch from
main, change the.tffiles of the stack, open a PR. - Plan runs
fmt -check,init,validateandplanfor every stack the PR touches (all of them whenshared/or the workflows change) and comments each plan on the PR. Read it: it is exactly what will change. - Merge to
main. - Run Apply by hand (Actions → Apply → stack or
all). It needs theproductionenvironment approval, plans again onmainand applies.
| Name | Kind | Use |
|---|---|---|
CLOUDFLARE_API_TOKEN |
secret | Scoped API token "infra terraform": DNS, email routing, workers routes, zone read on univerlab.org; Access apps, Pages, R2, KV, Turnstile, Workers scripts on the account |
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY |
secret | R2 S3 credentials limited to the univerlab-tfstate bucket |
RESEND_API_KEY |
secret | The site's mail key, set on the univerlab Pages project |
CLOUDFLARE_ACCOUNT_ID, R2_ENDPOINT |
variable | Account id and the R2 S3 endpoint |
Locally the same values live in ~/.config/univerlab/infra.env (mode 600):
set -a; . ~/.config/univerlab/infra.env; set +a
export TF_VAR_account_id=$CLOUDFLARE_ACCOUNT_ID
cd stacks/dns
terraform init -backend-config="endpoints={s3=\"$R2_ENDPOINT\"}"
terraform planEverything was imported from the live account with cf-terraforming on
2026-11-18 and the import blocks were removed once applied. To adopt something else
later: cf-terraforming generate + import --modern-import-block for that
resource type, move the result into the right stack, and plan until it shows
only imports.