Here at Chromatic, we are on a never-ending mission to get as many things as possible into version control as possible. Next step? DNS configuration.
dnscontrol is an open-source tool written in Go by the fine folks at Stack Exchange that allows us to configure our DNS records in a JS file that can be committed to version control and published on demand. It supports a number of DNS providers including AWS Route 53, DNSimple, and NameCheap. With this configuration in git, we can now easily review changes through our normal pull request workflow, as well as getting a full log of any changes made over time.
Working With dnscontrol
Configuration is done via a
dnsconfig.js file and looks something like the example below, defining both a registrar and DNS provider and then configuring the records in each zone.
var namecom = NewRegistrar("name.com", "NAMEDOTCOM"); var r53 = NewDnsProvider("r53", "ROUTE53"); D("example.com", namecom, DnsProvider(r53), A("@", "18.104.22.168"), AAAA('@', '2001:db8:a0b:12f0::1'), A("test", "22.214.171.124"), CNAME("www", "@"), MX("@", 5, "mail.myserver.com."), );
dnscontrol preview is similar to a diff in that it compares the configuration in your code to what is published on the DNS name servers. Its output highlights any records that would be created, modified, or removed were you to run
dnscontrol push takes the configuration state in your config file and publishes it live to your DNS name servers.
Now Let’s Automate
Even better, now that we are committing our DNS records to version control and putting them to our review process, we can automate the publishing of those changes when we merge the changes. A simple Jenkins job will suffice that is triggered on merge and runs