INF-35Recommended
Keep DNS records in code
Manage every DNS record of every domain in code, changed by pull request. Never edit a record in the provider's web panel.
How to do it
Use a tool such as OctoDNS, DNSControl or a Terraform provider for your DNS host. Keep mail, verification and certificate records there too. Run the tool's preview in the pull request and apply from CI. Add records from the CAA and DNSSEC rules. Remove records for retired services as in dangling DNS.
Examples
Terraform example
# A DNS host's provider, here Cloudflare's
resource "cloudflare_dns_record" "apex" {
zone_id = var.zone_id
name = "example.com"
type = "A"
content = "203.0.113.10"
ttl = 3600
}
YAML example
# OctoDNS: config/example.com.yaml
'':
- type: A
value: 203.0.113.10
- type: CAA
value: { flags: 0, tag: issue, value: letsencrypt.org }
www:
type: CNAME
value: example.com.
How to check
A daily job runs the tool's preview against the live zone. It reports no difference.
Related rules
- WEB-15 Say in DNS if a domain is for sale in Website
- EML-9 Publish an SPF record in Email
- WEB-162 Choose who may issue your certificates in Website
- WEB-163 Sign your DNS in Website
- APS-68 Remove DNS records you no longer use in Application security
- INF-68 Own the domain and DNS in your own accounts in Infrastructure and environments
- STK-59 Use a managed DNS and CDN that exports your zone in Software choices
- AGT-64 List agent endpoints in DNS in Agents as users
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/infrastructure/networking-and-dns/dns-as-code">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.