ADR-INFRA-012 — Mail Records With the Zone

By Engineering & Architecture Team•December 5, 2026•4 min read

Status: Accepted Date: 2026-12-05 Authors: Engineering & Architecture Team

Context

The project-setup layer (L2) creates each environment’s zone. After the L2 apply, a person points the domain’s nameservers at Cloudflare at the registrar (SR-INFRA-009 SR-F-10). From that moment the Cloudflare zone answers every DNS question for the domain, and the records still listed at the registrar are ignored.

If the mail records the domain’s mailbox needs are declared by a later layer, the zone has no MX record between the nameserver switch and that layer’s apply, which can be hours or days later on its own release schedule; in that window the domain receives no mail and the mail provider reports it as disconnected. Mail records also belong to the domain, not to the website: a domain keeps its mailbox whether or not a site is deployed on it.

Decision Drivers (FRs & NFRs)

  • BRD-INFRA-009 BR-1.7 — pointing a domain at the provider never interrupts its email.
  • SR-INFRA-009 SR-F-10 — the nameserver step follows the zone’s creation, by hand.
  • SR-INFRA-009 SR-F-13 — mail records are declared with the zone and applied before the nameserver step.
  • SR-INFRA-009 SR-F-04 — the site layers declare only the site’s own resources.
  • SR-INFRA-009 SR-NF-09 — the project-setup credential’s added DNS permission is used for mail records only.
  • Workspace rule 10 section 1 — every record is declared in code and reviewed; none is added by hand.

Decision — Which layer owns a domain’s mail records

Option 1 — The site layers (L3, L4)

The site module declares the mail records next to the site’s apex and www records.

Pros:

  • The project-setup credential needs no DNS permission.
  • All of a zone’s records are declared in one module.

Cons:

  • Mail stops between the nameserver switch and the next site apply, because the zone exists before the site layer runs.
  • The domain’s mail depends on the website’s release life cycle and on its pipeline credentials being valid.
  • A site removed from a domain would take the domain’s mail records with it.

Option 2 — The project-setup layer, with the zone (CHOSEN)

The project-setup module declares each zone’s mail records (email.tf, input email_dns_records keyed by project), applied in the same run that creates the zone, before the nameserver step.

Pros:

  • The zone answers mail queries from its first minute; the nameserver switch never interrupts mail.
  • Mail records live with what they belong to, the domain, and do not depend on a site release.
  • Production gets its mail records from its own setup run before its live domain moves.

Cons:

  • The hand-made project-setup credential gains DNS edit on the account’s zones, used only for mail records.
  • A zone’s records are declared in two places: mail records in L2, site records in L3 and L4.

Option 3 — Added by hand in the dashboard

A person adds the records in the dashboard before the nameserver switch.

Pros:

  • No code and no extra permission.

Cons:

  • Drift: no review, no record in state, and a later apply of a layer that does declare them fails on an identical existing record.
  • Against workspace rule 10 section 1.

Option 4 — A separate mail root module

A fifth root module only for mail records, applied after L2.

Pros:

  • Its own narrow credential, holding DNS edit only.

Cons:

  • A new state file, passphrase, credential and run for a handful of records, and one more manual step between the zone and the nameserver switch, which is the gap this decision closes.

Final Decision

Option 2: the project-setup layer creates each zone’s mail records in the same run as the zone, so the domain’s mail works before its nameservers move. Option 1 is rejected for the mail outage window and for tying the domain’s mail to the website’s release cycle; Option 3 for drift and the missing review; Option 4 for the extra layer and the extra step.

Accepted cost: the hand-made project-setup credential, which already can create zones and tokens, also holds DNS edit, used only for mail records; the site’s apex and www records stay with the site layer.