Skip to content

infra: bring the Cloudflare zone under Terraform (and give CI a scoped read-only token) #908

Not planned

Description

@athvin

Backlog. Prerequisite for moving the sccache bucket to Cloudflare R2 (see the
follow-up ticket), but worth doing on its own terms: the Cloudflare zone is
currently a second, unmanaged source of truth for infrastructure this repo
otherwise declares entirely in Terraform.

Current state, which is further along than it looks

  • §18.8 resolved the DNS plane to Cloudflare (2026-10-10): dupezero.com is
    registered at Cloudflare Registrar, which pins the apex to Cloudflare's
    nameservers, so there is deliberately no Route 53 zone — a second zone
    would be a second DNS authority for one domain.
  • The provider is already declared: cloudflare/cloudflare ~> 5.0 in
    infra/terraform/envs/dev/versions.tf, with provider "cloudflare" {}
    reading CLOUDFLARE_API_TOKEN from the environment. That is deliberate and
    should be preserved — a Terraform variable would write the token into the
    plan file and into state.
  • infra/terraform/envs/dev/ses.tf already writes the SES Easy-DKIM and
    MAIL FROM records into the zone.
  • er-platform's ingress pins
    external-dns.alpha.kubernetes.io/cloudflare-proxied: "false", because dev
    hostnames resolve to an internal tailnet-reached ALB that Cloudflare's proxy
    could never reach.

What is actually unmanaged

  1. The zone, the registrar record, the apex and the nameservers — all
    hand-created. Nothing imports them.
  2. ses.tf has never been applied. Its own comment says so:
    terraform state list matched no ses/cloudflare/mail resources.
  3. The opt-in hack is the symptom to fix, and it is the crux. Both SES
    variables default to null so the file contributes nothing when unset. The
    reason is §14.2 / PR feat(infra): terraform plan on every PR, apply on main behind a reviewer gate #352: once terraform plan became a CI gate, a missing
    CLOUDFLARE_API_TOKEN meant the provider could not authenticate, the whole
    envs/dev plan failed, and the 101 resources that do plan cleanly were never
    checked.
    Making SES opt-in was the workaround.
  4. external-dns's scoped token (Secrets Manager, §18.8) is specified but the
    path is blocked on task 1.4 and ingress.enabled: false.
  5. The demo share tunnel — a public trycloudflare link, currently paused.
    It is off-design and carries documented teardown steps. Either bring it under
    Terraform or tear it down; leaving it is the worst of the three.

The thing to actually solve

How a Cloudflare credential reaches CI without granting write. This is what
blocks everything else, and it has a clean answer worth confirming: Cloudflare
API tokens are scopable, so

  • a read-only zone-scoped token as a GitHub secret lets terraform plan
    authenticate on every PR, which removes the opt-in hack and puts the records
    back under the gate;
  • a write token, available only to the apply path on main, does the
    mutating half.

That split is the same shape as er-ci-sccache-read / er-ci-sccache-write,
and the same shape the R2 follow-up needs for cache-poisoning protection.

Scope

  • Decide and document the token story above; put the read-only token in
    place and confirm envs/dev plans end-to-end in CI with SES enabled
  • Remove the ses.tf opt-in defaults once a plan no longer needs them
  • terraform import the zone and the existing records; plan must come back
    empty afterwards, which is the only real proof the import was faithful
  • Decide the Terraform home: a cloudflare module plus a core-level
    stack, since the zone is account-wide rather than per-environment, and
    envs/dev is the wrong owner for an apex
  • Resolve the demo tunnel: import or tear down
  • Apply ses.tf for real, and confirm the DKIM records resolve

Watch out for

  • cloudflare_record was v4; v5 renamed it cloudflare_dns_record, and
    versions.tf already notes this.
  • Importing a zone you do not fully enumerate first produces a destructive plan.
    Enumerate every record before writing any HCL.
  • infra.yml's destroy guard and the house rule that no agent session applies
    Terraform both still hold here.

Activity

  1. added
    pruned
    on Nov 27, 2026
  2. athvin commented on Nov 27, 2026

    @athvin
    OwnerAuthor

    Closed in the 2026-11-26 board prune. The board now targets a deduplication tool that works the same whatever the data's source. This card is speculative or process upkeep, so it isn't needed for that. It's labelled pruned and can be reopened if it becomes relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pruned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions