Skip to content

Platform Terraform — Lovely Home Hub ​

Provisions isolated hub sites on Cloudflare (D1, R2, Pages, DNS, Zero Trust Access). Worker code deploy and D1 migrations stay in Wrangler/CI.

Site registry: platform/sites.yaml.

What Terraform manages ​

ResourcePer site
D1lovely-home-appliance-manuals-{site}
R2guides + media buckets
Pageshome-dashboard-{site} + env vars + HUB_API binding
DNS{hostname} CNAME → Pages project subdomain (not {project_name}.pages.dev — legacy production uses home-dashboard-a11.pages.dev)
AccessPages hostname + Worker *.workers.dev apps + email policies

Production can be imported into Terraform (legacy names: home-dashboard, lovely-home-hub-api). Use scripts/terraform-plan-production-safe.sh before apply. Test and sandbox are Terraform-managed.

Terraform stacks (ring-fenced state) ​

Two remote states share the same R2 bucket, and each household hub on the customers stack has its own file so two signups can apply at once:

StackBackend keyWhat it owns
platformhome-dashboard/platform.tfstatePlatform admin, marketing Access, marketing www → apex redirect, *.lovely-home.co.uk hubs
customers (combined, backup)home-dashboard/customers.tfstateLeft in place after the per-site split — do not apply against it
customers (per site)home-dashboard/customers/{siteId}.tfstateOne *.lovely-hub.com household hub

| platform (sandbox) | home-dashboard/platform-sandbox.tfstate | Sandbox platform admin + marketing (platform-sandbox.lovely-home.co.uk) — applied by hand, see Sandbox platform state |

var.terraform_stack filters module.hub_site (and skips platform_admin / marketing_site on the customers stack). Customer applies also pass var.provision_site_id so that per-site state cannot recreate every other hub from sites.yaml. Always pass -var=terraform_stack=… — the Terraform default is platform, which would destroy customer hubs if applied against a customers backend.

One-time split from the legacy combined home-dashboard/hub.tfstate (done in September 2026): bash scripts/migrate-terraform-state-stacks.sh split-stacks, then peel household hubs out of the combined customers file with bash scripts/migrate-terraform-state-customer-sites.sh split-sites. Their GitHub Actions were removed once both had run. See platform-provision.md.

Sandbox platform state ​

The sandbox platform has its own state and is not applied by CI, so changes to modules/platform_admin (e.g. new Access bypass apps) reach it only when you apply it by hand.

Use the wrapper — it loads the matching state and tfvars together, so they can't be mixed up (#961):

bash
# check the token first — a wrong/narrow token shows up as 403 auth.forbidden on every read
curl -s -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" https://api.cloudflare.com/client/v4/user/tokens/verify

bash scripts/tf-platform.sh sandbox plan -target=module.platform_admin
bash scripts/tf-platform.sh sandbox apply -target=module.platform_admin

bash scripts/tf-platform.sh production plan -target=module.platform_admin   # production, same way

It re-inits with -backend-config=key=… (so environments/backend.hcl stays on production — never edit it to switch stacks), refuses if the tfvars' platform hostname doesn't match the stack, and always passes -var=terraform_stack=platform.

Guard rails ​

  • terraform_data.state_guard (in module.platform_admin) records the platform hostname in each state with prevent_destroy. Planning one platform's tfvars against the other platform's state would replace it, so the plan fails with Instance cannot be destroyed … state_guard. That error means "wrong state loaded" — re-init for the right stack; don't remove the guard. It arms after one apply per state.

  • Production is applied by the Platform admin Terraform workflow, which generates its tfvars from GitHub secrets. tf-platform.sh production apply refuses (exit 3) unless ALLOW_LOCAL_PRODUCTION_APPLY=1, and plan warns. On 19 Oct 2026 a local production plan with a hand-kept hub.tfvars wanted to destroy 7 resources (#966):

    • the marketing Access apps;
    • the hub-jobs queue consumers;
    • the signup edge rate limit;
    • the social media domain.

    The causes were marketing_site_access_protected, manage_hub_queue_consumers and the signup settings differing from the workflow's values, plus a social resource missing from the code (#967).

  • cloudflare_d1_database.platform_billing has prevent_destroy: Terraform can never replace or delete the billing database.

On 19 Oct 2026 a plan with sandbox-hub.tfvars against production state wanted to destroy the demo hub, marketing Access, ops handbook and social stack, and replace the production billing D1 — these guards make that plan error out instead.

If the plan also wants to change cloudflare_pages_project.admin (env vars) or cloudflare_workers_script.hub_jobs, check it against your tfvars: the Pages env-var list is rewritten in full, so variables added by hand in the Cloudflare dashboard are removed.

Prerequisites ​

  1. Cloudflare API token (not the Global API Key, not Wrangler OAuth). Create at Profile → API Tokens.

    Recommended: Custom token → Edit Cloudflare Workers template, then ensure these permissions:

    ScopePermission
    Account → D1Edit
    Account → Workers R2 StorageEdit
    Account → Cloudflare PagesEdit
    Account → Access: Apps and PoliciesEdit
    Account → Access: Service TokensEdit
    Account → Workers ScriptsEdit
    Account → Account SettingsRead
    Zone → lovely-home.co.uk → DNSEdit
    Zone → lovely-home.co.uk → Workers RoutesEdit
    Zone → lovely-home.co.uk → ZoneRead
    Zone → lovely-home.co.uk → Single RedirectEdit (the www → apex ruleset, #1355; Cloudflare used to call this permission Dynamic Redirect)
    Zone → lovely-home.co.uk → Zone SettingsEdit (Browser Cache TTL "Respect existing headers", #1431)

    Account resources: include your account. Zone resources: include lovely-home.co.uk.

    Verify before apply:

    bash
    export CLOUDFLARE_API_TOKEN="..."
    export CLOUDFLARE_ACCOUNT_ID="your-account-id"
    export CLOUDFLARE_ZONE_ID="your-zone-id"
    bash scripts/verify-cloudflare-api-token.sh

    Terraform reads CLOUDFLARE_API_TOKEN automatically (do not put the token in *.tfvars unless you use TF_VAR_ — the provider block is intentionally empty).

  2. GitHub account linked to Cloudflare Pages (one-time dashboard step).

  3. Terraform ≥ 1.5.

  4. Wrangler logged in for deploy + secrets (npx wrangler login).

    Terraform token ≠ Wrangler token. After terraform apply, run Worker commands with OAuth, not the Terraform API token:

    bash
    unset CLOUDFLARE_API_TOKEN   # otherwise wrangler reuses it and secret put fails
    cd worker
    npx wrangler login           # browser OAuth — one-time until session expires
    npm run deploy:sandbox
    npx wrangler secret put HUB_PROXY_SECRET --env sandbox

    Alternatively, add Account → Workers Scripts → Edit to your API token and keep CLOUDFLARE_API_TOKEN set — that permission covers deploy and wrangler secret put. OAuth is simpler for local setup.

First-time sandbox ​

bash
# 1. Configure vars (attach_hub_api_binding = false until Worker exists)
cp terraform/environments/sandbox.tfvars.example terraform/environments/sandbox.tfvars
# Edit with account ID, zone ID, real owner emails

export CLOUDFLARE_API_TOKEN="..."
cd terraform
terraform init
terraform plan -var-file=environments/sandbox.tfvars
terraform apply -var-file=environments/sandbox.tfvars

# 2. Sync D1 id into wrangler + deploy Worker (OAuth — not terraform token)
cd ..
unset CLOUDFLARE_API_TOKEN
node scripts/sync-wrangler-from-terraform.mjs sandbox
cd worker
npx wrangler login
npm run d1:migrate:sandbox
npm run deploy:sandbox
bash ../scripts/post-terraform-site-setup.sh sandbox

# 3. Enable HUB_API binding in Terraform (Worker must exist first)
#    In sandbox.tfvars set attach_hub_api_binding = true on the sandbox site (default), then:
cd ../terraform
terraform apply -var-file=environments/sandbox.tfvars

# 4. Deploy Pages frontend
bash ../scripts/deploy-cloudflare-pages-site.sh sandbox
# Open https://sandbox.lovely-home.co.uk/api/access-probe while logged in

Pages not deploying (“No production deployment yet”) ​

Terraform creates the Pages project and env vars; it does not upload a build.

SettingValueEffect
production_branchmainGit source stays connected (previews, dashboard)
Hub production_deployments_enabledfalseRegistry merges do not rebuild every household. Provision wrangler-deploys; app-code rollouts use cd-hub-pages.yml (manual CD)
Platform admin production_deployments_enabledtruemain still rebuilds home-dashboard-platform
Hub preview_deployment_settingnone in TerraformAvoids Cloudflare 8000022 when PATCHing Pages with HUB_API bindings
pages_preview_deployments_enabledtrue (platform admin only)Platform admin project gets preview builds via Terraform
Hub branch previewsnode scripts/enable-hub-pages-previews.mjsRun after apply when you want hub site preview URLs

Preview URLs look like https://{branch}.{project}.pages.dev. Platform admin previews are Terraform-managed; hub sites (demo, test, sandbox) use the enable script because the Terraform provider cannot safely PATCH preview settings and HUB_API service bindings together.

Access: Custom domains (platform.lovely-home.co.uk, demo.lovely-home.co.uk) have Terraform-managed Access apps. Preview *.pages.dev hostnames may need a separate Access application (wildcard or per-branch) — see cloudflare-access-runbook.md.

If preview rows show “No deployment available”, either previews are disabled (pages_preview_deployments_enabled = false) or Terraform has not been applied since enabling them.

If apply fails on existing sites with Invalid Service name () (8000022) when updating Pages, hub site pages.tf keeps preview_deployment_setting = "none" in Terraform — use node scripts/enable-hub-pages-previews.mjs after apply instead.

First production deploy (when the project has never built):

bash
unset CLOUDFLARE_API_TOKEN
npx wrangler login
bash scripts/deploy-cloudflare-pages-site.sh sandbox

Option B — dashboard: Workers & Pages → home-dashboard-sandbox → Create deployment → branch main.

Option C — roll out app code: Actions → CD — Hub Pages (cd-hub-pages.yml) builds once and wrangler-deploys selected hubs (or all). Registry-only merges do not deploy.

After the first Pages deploy, ensure the Worker is up (npm run deploy:sandbox + secrets from post-terraform-site-setup.sh).

access_team_domain in tfvars must match Zero Trust → Settings (https://{team}.cloudflareaccess.com), not the Workers *.workers.dev subdomain. Wrong value causes “Unable to find your Access organization” on login.

HUB_API Pages binding ​

Terraform manages Pages env vars on create; lifecycle { ignore_changes = [deployment_configs] } stops later applies from PATCHing deployment configs (the provider returns 8000022 or unknown environment on service bindings).

HUB_API is attached with:

bash
bash scripts/deploy-cloudflare-pages-site.sh <site_id>

(or node scripts/attach-hub-api-pages-binding.mjs {site_id} then redeploy Pages — the deploy script attaches first and then deploys, so a new hub never serves a deployment without its API, #1500).

CI runs this after Worker deploy. Local full applies skip deployment config changes — run the deploy script after Worker deploy if health checks show HUB_API binding no.

Site block flagMeaning
attach_hub_api_binding = true in sites.yamlSite is fully provisioned; health checks expect HUB_API
attach_hub_api_binding = falsePre-worker / first apply only in CI generated tfvars

Production (home-dashboard) is not in this Terraform stack — configure HUB_API → lovely-home-hub-api in the dashboard as today.

tfvars hygiene ​

Use real values in hub.tfvars (never commit it):

  • hub.tfvars must list every site with terraform: true in platform/sites.yaml. If you add a site via the platform wizard but omit it from local hub.tfvars, the next terraform apply -var-file=environments/hub.tfvars destroys that site's Cloudflare resources. Before any local apply, run:
    bash
    node scripts/validate-local-hub-tfvars-sites.mjs
    Or generate tfvars from the registry (same as CI): node scripts/generate-hub-tfvars.mjs with the required env vars, then apply using hub.generated.tfvars.
  • owner_emails — must match who should pass Access. Placeholder emails in tfvars will overwrite the Owners policy on apply. Sitters, family and invited owners are the hub's: Terraform reads them from the live Access apps on each plan and keeps them (cloudflare-access.md, #1274).
  • hub_proxy_secret — required when importing a site; preserves existing Pages/Worker proxy secret.
  • access_team_domain — Zero Trust team slug (lovely-home), not the Workers subdomain.

Add a tester (sandbox / test only) ​

Terraform manages Access policies — do not add tester emails in the Cloudflare dashboard; the next apply will overwrite manual edits.

  1. Add the email under sites.{site_id}.tester_emails in local hub.tfvars (not global owner_emails, or they will get production too).
  2. Validate site list: node scripts/validate-local-hub-tfvars-sites.mjs
  3. Apply: cd terraform && terraform apply -var-file=environments/hub.tfvars
  4. Sync Worker owner list: node scripts/set-worker-secrets-from-terraform.mjs {site_id} (e.g. sandbox, test)

The tester must sign in with that exact email address for OTP. Without step 4 they may pass Access but get 403 on owner API routes (calendar, backup, …).

Pages preview Access ("invalid redirect URL") ​

PR preview URLs look like https://{hash}.home-dashboard-a11.pages.dev. Cloudflare Access must allow that hostname for OAuth to succeed.

Terraform-managed hub and platform Pages Access apps include three destinations (same CF_ACCESS_AUD_PAGES everywhere):

  • Custom domain (e.g. dashboard.lovely-home.co.uk)
  • Default Pages hostname (e.g. home-dashboard-a11.pages.dev)
  • Preview wildcard (e.g. *.home-dashboard-a11.pages.dev)

After enabling preview builds (PR #84), run terraform apply once so Access destinations update. Preview env vars already copy production CF_ACCESS_AUD_PAGES via enable-hub-pages-previews.mjs — the AUD stays the same; the app must cover preview hostnames.

If login still fails:

  1. Zero Trust → Access → Applications — remove duplicate manual apps for the same *.pages.dev host (keep the Terraform app Lovely Home — {site} Pages).
  2. Pages → project → Settings — if "Enable access policy" created extra auto apps, follow Cloudflare Pages known issues so only the Terraform apps apply.
  3. Redeploy the preview from the PR checks tab.

Outputs contract ​

bash
terraform output -json sites

Each site exposes d1_database_id, access_pages_aud, access_worker_aud, access_aud_combined, worker_api_origin, etc. — intended for scripts and a future platform admin UI.

Secrets (not in Terraform state for Worker) ​

post-terraform-site-setup.sh prints Wrangler commands for:

  • HUB_PROXY_SECRET (from terraform output -json hub_proxy_secrets)
  • CF_ACCESS_AUD (access_aud_combined from site contract)
  • CF_ACCESS_TEAM_DOMAIN, OWNER_EMAILS, dummy PRIVATE_* for vanilla sites

Pages receives HUB_PROXY_SECRET and CF_ACCESS_AUD_PAGES from Terraform.

Platform admin (operator dashboard) ​

Separate from hub sites — Mark-only UI at platform.lovely-home.co.uk (optional):

Operators come from the platform billing D1, not tfvars (see platform-admin.md).

hcl
platform_admin = {
  enabled  = true
  hostname = "platform.lovely-home.co.uk"
}

See platform-admin.md. Output: terraform output -json platform_admin.

Platform cannot reach hubs: healthAuthConfigured=false (#1364) ​

https://platform.lovely-home.co.uk/api/public/account/status → hubSetupTemplatesApply.healthAuthConfigured must be true, or Access-protected hubs refuse every platform call (Account → Stays, Cleaners, Billing). When it is false, run Platform refresh health token (confirm=refresh-health-token): it writes PLATFORM_HEALTH_CF_ACCESS_CLIENT_ID and _SECRET from the GitHub secrets onto home-dashboard-platform production in place (scripts/set-platform-pages-health-token.mjs, one PATCH, no Terraform), retries the production deployment and waits for the flag. GitHub secrets are the source of truth for that token (#1223). For archiveSecretConfigured=false, run Platform refresh archive secret instead.

Why it happened, and why it can't recur (#1364). The Cloudflare Terraform provider (v5) PATCHes only the half of a Pages env var entry that changed. A new value goes out without its type, and Cloudflare stores it as plain_text; a new type goes out without its value, and Cloudflare stores an empty secret. So a secret rotated through Terraform turns plain_text on one apply, and the next apply puts the type back and blanks it. That is what happened to the health token: the 2026-11-01 21:21 apply rewrote PLATFORM_HEALTH_CF_ACCESS_CLIENT_SECRET's value (it differed from state since the manual fix of #1223) and Cloudflare stored it as plain_text; the 2026-11-02 13:49 apply planned type = "plain_text" -> "secret_text" and left it empty. #1221 (the archive secret) was the same second step. Platform admin Terraform now saves each attempt's plan as JSON and, straight after the apply, runs scripts/write-platform-pages-env-from-plan.mjs: every env var entry the plan created or changed, on production and preview, is written again whole ({ type, value }) in one PATCH. The type comes from the plan (the config), the value from the plan or, when the plan only knew it as "known after apply", from the state. It prints names and types only, and the plan and state files are deleted when the job ends. This replaced the "Refresh platform Pages archive secret" step that ran after every apply.

The post-apply check waits for the new deployment. scripts/retry-platform-pages-production-deploy.mjs records the deployment the retry created (before #1364 it reported the id of the deployment it retried) as PLATFORM_EXPECTED_DEPLOYMENT_ID, and scripts/verify-platform-archive-runtime.mjs waits until that deployment serves the custom domain (canonical_deployment, stage deploy: success) before it reads /api/public/account/status. Before, the 13:49 check read the status one second after the retry, from the previous deployment, and passed. The same scripts run in Platform refresh health token and Platform refresh archive secret.

www → apex redirect ruleset already in Cloudflare (error 20217) ​

A zone holds one ruleset in the http_request_dynamic_redirect phase. A Single Redirect made in the dashboard creates it, and deleting that rule leaves the empty ruleset behind, so terraform apply of module.platform_admin[0].cloudflare_ruleset.marketing_www_to_apex[0] (#1355) fails with 'zone' is not a valid value for kind because exceeded maximum number of zone rulesets (#1362). Platform admin Terraform runs scripts/import-marketing-www-redirect.sh before the apply: it reads the phase entrypoint and imports it as zones/{ZONE_ID}/{RULESET_ID} when state does not have it, and the apply then replaces its rules with the www → apex rule. By hand:

bash
bash scripts/import-marketing-www-redirect.sh -var-file=environments/hub.tfvars -var=terraform_stack=platform

Browser cache TTL (#1431) ​

terraform/modules/platform_admin/marketing_cache.tf sets the zone's Browser Cache TTL to 0 ("Respect existing headers"), production platform state only. Cloudflare's default of 4 hours replaced the max-age=0, must-revalidate Pages sends for CSS, JS and images, so after a deploy a phone could show new HTML with an old site.css or locales/*.js (raw keys like account.moreTitle). Check it with curl -sI https://lovely-home.co.uk/site.css → cache-control: public, max-age=0, must-revalidate. Long caching belongs in website/_headers (only /fonts/*, whose file names change with the font).

hub-jobs Worker shows in every plan (#1433) ​

Before #1433, every Platform admin plan showed cloudflare_workers_script.hub_jobs "will be updated in-place" with nothing really changed. hub_jobs.tf left out the observability fields that Cloudflare fills in (head_sampling_rate = 1, a disabled traces block). Provider v5 then planned to remove them on every run, and each apply re-sent the script and Cloudflare added them back. The config now writes out every observability field Cloudflare stores. If this resource shows up in a plan again with only observability lines, compare those lines with the config and add whatever new default Cloudflare reports. Code changes are different: deploy-on-merge uploads workers/hub-jobs/index.js straight away, so after a hub-jobs code change the next plan shows a content update until the next apply, which re-uploads the same file.

Grafana M2M APIs (Access bypass) ​

platform_admin also creates Access bypass apps for Infinity/Grafana (service-token headers validated in Pages Functions — not OTP):

PathTerraform resourceNotes
/api/platform/social-insightsplatform_social_insightsSocial + website + Stripe billing block
/api/platform/ai-usageplatform_ai_usageWorkers AI + OpenAI + Claude placeholder
/api/platform/cloudflare-billingplatform_cloudflare_billingBillable Usage API + Workers + storage (Grafana)

Matching skips in functions/lib/platformAccessBypass.js are required or Grafana gets Access login 302 and No data. Details: Grafana dashboards.

Adding another site ​

  1. Add entry to platform/sites.yaml with terraform: true.
  2. Add matching block to terraform/environments/*.tfvars.
  3. Add [env.{site_id}] to worker/wrangler.toml (or run sync script after first apply).
  4. terraform apply → sync wrangler → migrate → deploy.

Hourly cron and AI binding (#846). Wrangler does not inherit the top-level [triggers] or [ai] into named environments, so each [env.{site_id}] needs its own [env.{site_id}.triggers] (crons = ["0 * * * *"]) and [env.{site_id}.ai]. Without the cron, a hub never runs its hourly job (sitter stay schedule, invited-owner Access re-sync). The new-site template in platform-site-manage.mjs includes both, sync-wrangler-from-terraform.mjs adds any that are missing, and tests/wranglerHubEnvDefaults.test.js fails CI if any env lacks one. A trigger only takes effect on the next wrangler deploy --env {site_id}.

Destroy a site ​

Automated (v5): delete via the platform admin wizard → merge the PR → platform-site-deprovision.yml runs on push to main. See platform-provision.md.

Manual (local):

bash
cd terraform
terraform destroy -var-file=environments/sandbox.tfvars \
  -target='module.hub_site["sandbox"]'

Or use node scripts/deprovision-hub-site.mjs {site_id} after removing the site from platform/sites.yaml.

Warning: destroys D1 data and R2 buckets for that site.

Importing existing test/production ​

Use when a site was provisioned manually (see cloudflare-test-environment.md) and you want Terraform to manage it without recreating D1/R2/Pages/Access/DNS.

Production: import when ready — see Import production below. Until import completes, keep terraform: false in platform/sites.yaml.

Import test (step-by-step) ​

  1. Merge site into tfvars — add test with terraform = true to your var-file (see terraform/environments/hub.tfvars.example). Keep sandbox in the same file if it is already in state.

  2. Preserve HUB_PROXY_SECRET — copy the existing value from the test Pages project and test Worker. Set hub_proxy_secret on the test site block in tfvars (required so Terraform does not rotate secrets on apply).

  3. Remove Pages secret for import — Cloudflare cannot import a Pages project while HUB_PROXY_SECRET exists as a secret env var in the dashboard. Delete it from home-dashboard-test → Settings → Environment variables → Production only. Terraform restores it on the next apply from hub_proxy_secret.

  4. Run the import script (from repo root):

    bash
    export CLOUDFLARE_API_TOKEN="..."
    cd terraform && terraform init
    bash ../scripts/terraform-import-hub-site.sh test -var-file=environments/hub.tfvars

    The script imports D1, R2×2, Access apps, Pages project, custom domain, and DNS CNAME into module.hub_site["test"].

  5. Review plan — expect some drift on Access app display names and Pages settings. Do not apply if the plan would replace D1 or R2 buckets.

    bash
    terraform plan -var-file=environments/hub.tfvars
  6. Apply when safe — reconciles Pages env vars (including restored HUB_PROXY_SECRET), DNS comment, Access policies, and HUB_API binding.

  7. Post-import — set terraform: true for test in platform/sites.yaml. With attach_hub_api_binding = true (default), /api/access-probe should show usesHubApiBinding: true after apply.

Worker deploy, D1 migrations, and Worker secrets remain Wrangler/CI — unchanged from the manual test stack.

Import production (step-by-step) ​

Production uses legacy Cloudflare names (no -production suffix):

ResourceName
Pageshome-dashboard
Workerlovely-home-hub-api
D1lovely-home-appliance-manuals
R2 guideslovely-home-appliance-guides
R2 medialovely-home-guide-media
  1. Add production to tfvars with terraform = true and hub_proxy_secret (copy from Pages home-dashboard and production Worker — must match).

  2. Remove Pages secret for import — delete HUB_PROXY_SECRET from home-dashboard → Settings → Environment variables → Production (Terraform restores it on apply).

  3. Import (same script as test):

    bash
    export CLOUDFLARE_API_TOKEN="..."
    cd terraform && terraform init
    bash ../scripts/terraform-import-hub-site.sh production -var-file=environments/hub.tfvars
  4. Plan carefully — expect drift on Access app display names (Lovely Home — Pages production vs module name). Do not apply if the plan replaces D1, R2, or destroys resources.

    bash
    terraform plan -var-file=environments/hub.tfvars
  5. Apply when safe — reconciles env vars, HUB_API binding, and platform health Access policy.

    If apply fails on cloudflare_pages_project with Invalid Service name () (8000022) or unknown environment on service bindings, hub Pages use lifecycle { ignore_changes = [deployment_configs] } — run node scripts/attach-hub-api-pages-binding.mjs {site_id} after Worker deploy instead.

    Optional guard before apply:

    bash
    bash ../scripts/terraform-plan-production-safe.sh -var-file=environments/hub.tfvars
  6. Post-import — set terraform: true in platform/sites.yaml and run npm run platform:manifest.

Production Worker deploy stays cd worker && npm run deploy (default env, not --env production).

DNS note: Legacy production Pages project name is home-dashboard but Cloudflare assigned subdomain home-dashboard-a11.pages.dev. The hub module CNAME must target cloudflare_pages_project.dashboard.subdomain, not {name}.pages.dev. Pointing at home-dashboard.pages.dev causes Error 1014 (CNAME Cross-User Banned).

Alternative: cf-terraforming ​

cf-terraforming can generate HCL and import IDs for comparison. Prefer the import script above when using this repo’s hub_environment module.