{"id":77313,"date":"2026-01-31T17:27:43","date_gmt":"2026-01-31T11:57:43","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=77313"},"modified":"2026-02-13T14:40:41","modified_gmt":"2026-02-13T09:10:41","slug":"dns-as-code-in-action-lessons-from-a-client-project-with-ns1-and-terraform","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/dns-as-code-in-action-lessons-from-a-client-project-with-ns1-and-terraform\/","title":{"rendered":"DNS as Code in Action: Lessons from a Client Project with NS1 and Terraform"},"content":{"rendered":"<h2><span style=\"text-decoration: underline;\"><strong>Introduction<\/strong><\/span><\/h2>\n<p>DNS is rarely the first thing teams modernise. In most client environments we work with at To The New, CI\/CD, cloud infrastructure, and observability mature quickly. DNS, however, often remains manually managed through dashboards, handled by a few people, and changed mostly during incidents. That gap usually goes unnoticed until traffic needs to be rerouted, a migration is planned, or an issue arises in production.<\/p>\n<div id=\"attachment_77308\" style=\"width: 635px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-77308\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-77308 size-large\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2026\/01\/Screenshot-2026-01-03-at-11.16.11\u202fAM-1024x681.png\" alt=\"DNS As Code\" width=\"625\" height=\"416\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2026\/01\/Screenshot-2026-01-03-at-11.16.11\u202fAM-1024x681.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2026\/01\/Screenshot-2026-01-03-at-11.16.11\u202fAM-300x200.png 300w, \/blog\/wp-ttn-blog\/uploads\/2026\/01\/Screenshot-2026-01-03-at-11.16.11\u202fAM-768x511.png 768w, \/blog\/wp-ttn-blog\/uploads\/2026\/01\/Screenshot-2026-01-03-at-11.16.11\u202fAM-624x415.png 624w, \/blog\/wp-ttn-blog\/uploads\/2026\/01\/Screenshot-2026-01-03-at-11.16.11\u202fAM.png 1166w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><p id=\"caption-attachment-77308\" class=\"wp-caption-text\">DNS As Code<\/p><\/div>\n<p>This blog shares how, in one of our ad-tech client projects, we transitioned DNS from manual operations to <strong>DNS as Code<\/strong>, utilizing <strong>NS1 (an IBM product) and Terraform<\/strong>, and what changes occurred afterward.<\/p>\n<h2><span style=\"text-decoration: underline;\"><strong>What We Found in the Client Setup<\/strong><\/span><\/h2>\n<p>The client had a reasonably mature DevOps setup:<\/p>\n<ul>\n<li>Infrastructure managed using Terraform<\/li>\n<li>Clear deployment pipelines<\/li>\n<li>Defined environments<\/li>\n<\/ul>\n<p>But DNS changes were different. They were:<\/p>\n<ul>\n<li>Made directly in the NS1 UI<\/li>\n<li>Applied mostly in production<\/li>\n<li>Not reviewed or documented<\/li>\n<li>Hard to trace during incidents<\/li>\n<li>DNS had effectively become a manual production dependency.<\/li>\n<\/ul>\n<h2><span style=\"text-decoration: underline;\"><strong>Why We Pushed for DNS as Code<\/strong><\/span><\/h2>\n<p>At To The New, our default approach is simple:<\/p>\n<ul>\n<li>If it affects production traffic, it should live in Git.<\/li>\n<li>DNS is the very first layer users hit. Managing it outside version control increases operational risk, especially when traffic routing and failover logic are involved.<\/li>\n<li>Since the client already used Terraform extensively, bringing DNS under the same workflow was a natural next step.<\/li>\n<\/ul>\n<h2><span style=\"text-decoration: underline;\"><strong>Why NS1 Fits This Approach<\/strong><\/span><\/h2>\n<p>NS1 wasn\u2019t just being used as a DNS provider; it was already part of the client\u2019s traffic management strategy. What worked in our favour:<\/p>\n<ul>\n<li>Support for weighted routing<\/li>\n<li>Metadata-based decisions<\/li>\n<li>Clear Terraform support<\/li>\n<li>This allowed us to model DNS behavior declaratively, rather than treating it as a static configuration.<\/li>\n<\/ul>\n<h2><span style=\"text-decoration: underline;\"><strong>Terraform + NS1: The Core Model<\/strong><\/span><\/h2>\n<p>In Terraform, you manage:<\/p>\n<ul>\n<li><strong>Zones<\/strong><\/li>\n<li><strong>Records<\/strong><\/li>\n<li><strong>Answers<\/strong><\/li>\n<li><strong>Metadata<\/strong><\/li>\n<li><strong>Routing behavior<\/strong><\/li>\n<li><strong>Everything lives in Git.<\/strong><\/li>\n<\/ul>\n<p>Provider Configuration<\/p>\n<pre>provider \"ns1\" {\r\n\u00a0 api_key = var.ns1_api_key\r\n}<\/pre>\n<p>This makes NS1 just another Terraform provider\u2014no special treatment, no UI dependency. Managing DNS Records Declaratively.<\/p>\n<p>Example: Simple A Record<\/p>\n<pre>resource \"ns1_record\" \"application_1\" {\r\n\u00a0 zone \u00a0 = \"demo.com\"\r\n\u00a0 domain = \"app1.demo.com\"\r\n\u00a0 type \u00a0 = \"A\"\r\n\u00a0 ttl\u00a0 \u00a0 = 60\r\n\u00a0 answers {\r\n\u00a0 \u00a0 answer = [\"10.53.1.98\"]\r\n\u00a0 }\r\n}<\/pre>\n<p>A DNS record is now:<\/p>\n<ul>\n<li><strong>Versioned<\/strong><\/li>\n<li><strong>Reviewable<\/strong><\/li>\n<li><strong>Reproducible<\/strong><\/li>\n<\/ul>\n<p>No surprises.<\/p>\n<p>Sample Command used for importing existing records into Terraform:<\/p>\n<pre>terraform import ns1_record.&lt;terraform_resource_name&gt; &lt;zone&gt;\/&lt;domain&gt;\/&lt;type&gt;<\/pre>\n<h2><span style=\"text-decoration: underline;\"><strong>Moving DNS into Terraform<\/strong><\/span><\/h2>\n<p>We started small. Existing records were recreated in Terraform, without changing behavior. The goal was not optimisation, it was control and visibility. Once records lived in code:<\/p>\n<ul>\n<li>Every change had a history<\/li>\n<li>Reviews became mandatory<\/li>\n<li>Ownership was clear<\/li>\n<li>DNS stopped being something \u201chandled on the side\u201d.<\/li>\n<\/ul>\n<h2><span style=\"text-decoration: underline;\"><strong>GitOps in Practice for DNS<\/strong><\/span><\/h2>\n<p>After this, DNS changes followed the same workflow as infrastructure changes:<\/p>\n<ul>\n<li>Change proposed through a pull request<\/li>\n<li>Terraform plan reviewed by the team<\/li>\n<li>Merge triggered Terraform apply<\/li>\n<li>NS1 updated records automatically<\/li>\n<li>No direct NS1 dashboard access was required for day-to-day work.<\/li>\n<\/ul>\n<p>This alone reduced risky, last-minute DNS changes significantly.<\/p>\n<h2><span style=\"text-decoration: underline;\"><strong>A Real Use Case: Gradual Traffic Migration<\/strong><\/span><\/h2>\n<p>One practical scenario where this helped was a backend migration. Instead of switching traffic in one go, we used weighted DNS routing to:<\/p>\n<ul>\n<li>Route a small percentage of traffic to the new backend<\/li>\n<li>Observe behavior in real traffic<\/li>\n<li>Gradually increase the load<\/li>\n<li>Each weight change was a Git commit.<\/li>\n<li>Each adjustment was reviewed.<\/li>\n<\/ul>\n<p>There was no ambiguity about what changed or when. Environment Consistency Improved Immediately.<\/p>\n<p>Before Terraform: DNS records for non-production environments were created manually and didn\u2019t always match production logic.<\/p>\n<p><strong>With DNS as Code:<\/strong><\/p>\n<ul>\n<li>Same structure across all environments<\/li>\n<li>Only the values differed<\/li>\n<li>No accidental drift<\/li>\n<li>Debugging environment-specific issues became much easier.<\/li>\n<li>Rollbacks Stopped Being Stressful<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><strong>Earlier, rolling back a DNS change meant:<\/strong><\/span><\/p>\n<ul>\n<li>Remembering the previous state<\/li>\n<li>Manually updating records<\/li>\n<li>Hoping nothing was missed<\/li>\n<\/ul>\n<p>With Terraform:<\/p>\n<ul>\n<li>Revert the commit<\/li>\n<li>Apply the change<\/li>\n<li>Done<\/li>\n<li>DNS rollbacks became routine instead of risky.<\/li>\n<\/ul>\n<h2><span style=\"text-decoration: underline;\"><strong>Lessons from the Implementation<\/strong><\/span><\/h2>\n<p>A few things we learnt during this project:<\/p>\n<ul>\n<li>Keep TTLs low for records involved in routing decisions<\/li>\n<li>Avoid making \u201cquick fixes\u201d directly in the UI<\/li>\n<li>Start with simple routing logic and evolve gradually<\/li>\n<li>Treat DNS changes like application changes<\/li>\n<li>DNS doesn\u2019t need to be complicated\u2014but it does need discipline.<\/li>\n<\/ul>\n<h2><span style=\"text-decoration: underline;\"><strong>Closing Thoughts<\/strong><\/span><\/h2>\n<p>DNS is often treated as background infrastructure. In reality, it\u2019s a critical part of the request flow and availability. In this client engagement, bringing DNS into the GitOps model using NS1 and Terraform:<\/p>\n<ul>\n<li>Reduced operational risk<\/li>\n<li>Improved confidence during changes<\/li>\n<li>Aligned DNS with the rest of the platform<\/li>\n<\/ul>\n<p>At <strong>To The New<\/strong>, this approach has now become a standard recommendation for teams using intelligent DNS at scale. DNS may be old, but how we manage it should reflect modern engineering practices.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction DNS is rarely the first thing teams modernise. In most client environments we work with at To The New, CI\/CD, cloud infrastructure, and observability mature quickly. DNS, however, often remains manually managed through dashboards, handled by a few people, and changed mostly during incidents. That gap usually goes unnoticed until traffic needs to be [&hellip;]<\/p>\n","protected":false},"author":1601,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":63},"categories":[2348],"tags":[8293,6620,1892,8289,8291,7603,6835,8290,7323,8292,1585,2987,6468],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/77313"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1601"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=77313"}],"version-history":[{"count":4,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/77313\/revisions"}],"predecessor-version":[{"id":77792,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/77313\/revisions\/77792"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=77313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=77313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=77313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}