<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>IaC on Ansuman Satapathy</title><link>https://ansuman-satapathy.github.io/categories/iac/</link><description>Recent content in IaC on Ansuman Satapathy</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sun, 25 Jan 2026 20:30:00 +0530</lastBuildDate><atom:link href="https://ansuman-satapathy.github.io/categories/iac/index.xml" rel="self" type="application/rss+xml"/><item><title>Terraform Best Practices: How to Not Nuke Production</title><link>https://ansuman-satapathy.github.io/blog/terraform-best-practices-how-not-to-nuke-production/</link><pubDate>Sun, 25 Jan 2026 20:30:00 +0530</pubDate><guid>https://ansuman-satapathy.github.io/blog/terraform-best-practices-how-not-to-nuke-production/</guid><description>&lt;p&gt;Writing Terraform is easy. Managing Terraform at scale without destroying your company’s infrastructure is hard.&lt;/p&gt;
&lt;p&gt;If your idea of &amp;ldquo;state management&amp;rdquo; is a file on your laptop named &lt;code&gt;terraform.tfstate.backup2&lt;/code&gt;, stop. Here are some tips to not embarrass yourself in front of management.&lt;/p&gt;
&lt;h3 id="1-remote-state-is-non-negotiable"&gt;1. Remote State is Non-Negotiable&lt;/h3&gt;
&lt;p&gt;If you work on a team (or ever plan to), your state file cannot live on your local machine.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Problem:&lt;/strong&gt; If two people run &lt;code&gt;terraform apply&lt;/code&gt; at the same time with different local states, you get a race condition that corrupts everything.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Fix:&lt;/strong&gt; Use a &lt;strong&gt;Remote Backend&lt;/strong&gt; (like AWS S3).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Lock:&lt;/strong&gt; Use &lt;strong&gt;DynamoDB&lt;/strong&gt; for state locking. This prevents &amp;ldquo;Person B&amp;rdquo; from writing to the state while &amp;ldquo;Person A&amp;rdquo; is still deploying.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-hcl" data-lang="hcl"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# backend.tf
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;terraform&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;backend&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;s3&amp;#34;&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; bucket &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;my-corp-terraform-state&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;prod/app-server/terraform.tfstate&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; region &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;us-east-1&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; dynamodb_table &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;terraform-state-locks&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; encrypt &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;img src="fear.png" alt="Fear" style="width: 100%; height: auto; border-radius: 8px;"&gt;
*Fig: Actual footage of a DevOps engineer looking at a local state file.*
&lt;h3 id="2-keep-it-dry-dummy"&gt;2. Keep it DRY Dummy!&lt;/h3&gt;
&lt;p&gt;Stop Copy-Pasting resource blocks. If you need 5 web servers, do not write the &lt;code&gt;aws_instance&lt;/code&gt; block 5 times. Use &lt;strong&gt;Modules&lt;/strong&gt;.&lt;/p&gt;</description></item></channel></rss>