<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[OrchesTerra Engineering]]></title><description><![CDATA[OrchesTerra Engineering]]></description><link>https://orchesterra.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6b102570767b27c002d6d295/130f1009-d300-4113-b5ff-7ec7128db665.png</url><title>OrchesTerra Engineering</title><link>https://orchesterra.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 21:21:08 GMT</lastBuildDate><atom:link href="https://orchesterra.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Terraform ignore_changes: When to Use It, and When It Hides Drift]]></title><description><![CDATA[How Terraform lifecycle ignore_changes works, when it is the right tool, ignoring single tag keys, and how to stop it hiding real drift.]]></description><link>https://orchesterra.hashnode.dev/terraform-ignore-changes</link><guid isPermaLink="true">https://orchesterra.hashnode.dev/terraform-ignore-changes</guid><category><![CDATA[Terraform]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Infrastructure as code]]></category><category><![CDATA[AWS]]></category><dc:creator><![CDATA[Akshay Kilam]]></dc:creator><pubDate>Wed, 02 Dec 2026 14:14:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b102570767b27c002d6d295/73e1c132-913d-4d28-9f73-29adebef479b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><code>ignore_changes</code> tells Terraform to stop correcting certain attributes of a resource. It is the right tool when something else legitimately owns a value, such as an autoscaler or a deploy pipeline. It is the wrong tool when someone changed a resource in the console and the next plan wanted to put it back. In that case it hides drift instead of fixing it.</p>
<p>This guide covers the syntax, the cases where it belongs, ignoring tags, the common errors, and how to keep it from becoming a place where drift goes unnoticed.</p>
<h2>How ignore_changes works</h2>
<p><code>ignore_changes</code> lives in a resource's <code>lifecycle</code> block and takes a list of attribute names:</p>
<pre><code class="language-hcl">resource "aws_ecs_service" "api" {
  name            = "api"
  cluster         = aws_ecs_cluster.main.id
  task_definition = aws_ecs_task_definition.api.arn
  desired_count   = 2

  lifecycle {
    ignore_changes = [desired_count]
  }
}
</code></pre>
<p>Terraform uses <code>desired_count = 2</code> when it creates the service. After that, if the real value changes (here, because Application Auto Scaling scaled the service to 6), <code>terraform plan</code> no longer proposes setting it back to 2.</p>
<p>Three details matter:</p>
<ul>
<li><strong>It only affects updates.</strong> The value in your code is still used when the resource is created or replaced.</li>
<li><strong>Terraform still reads the real value.</strong> A refresh records it in state, so <code>terraform state show aws_ecs_service.api</code> shows <code>desired_count = 6</code>. The plan simply doesn't act on it.</li>
<li><strong>Changing the code doesn't change the resource either.</strong> If you later edit <code>desired_count</code> to 4, nothing happens, because the attribute is ignored in both directions.</li>
</ul>
<h2>When ignore_changes is the right tool</h2>
<p>Use it when <strong>another system owns the value on purpose</strong>, and that ownership is stable:</p>
<table>
<thead>
<tr>
<th>Resource</th>
<th>Attribute</th>
<th>Who really owns it</th>
</tr>
</thead>
<tbody><tr>
<td><code>aws_autoscaling_group</code></td>
<td><code>desired_capacity</code></td>
<td>Scaling policies</td>
</tr>
<tr>
<td><code>aws_ecs_service</code></td>
<td><code>desired_count</code></td>
<td>Application Auto Scaling</td>
</tr>
<tr>
<td><code>aws_ecs_service</code></td>
<td><code>task_definition</code></td>
<td>A CI pipeline that deploys new task definitions</td>
</tr>
<tr>
<td><code>aws_lambda_function</code></td>
<td><code>image_uri</code> or code hash</td>
<td>A deploy tool outside Terraform</td>
</tr>
<tr>
<td><code>aws_db_instance</code></td>
<td><code>password</code></td>
<td>Secrets Manager rotation</td>
</tr>
<tr>
<td>Any resource</td>
<td>Specific tags</td>
<td>Tools that tag resources after creation (cost, backup, security scanners)</td>
</tr>
</tbody></table>
<p>In each case the change outside Terraform is expected, repeats, and is correct. Fighting it would make every plan noisy and every apply risky.</p>
<h2>Ignoring tags, or just one tag</h2>
<p>Ignoring all tags is a common overreach:</p>
<pre><code class="language-hcl">lifecycle {
  ignore_changes = [tags]
}
</code></pre>
<p>That also ignores tags your team changes in code, such as <code>Owner</code> or <code>CostCenter</code>. Ignore only the keys another tool writes:</p>
<pre><code class="language-hcl">lifecycle {
  ignore_changes = [tags["LastBackup"], tags["ScannerVersion"]]
}
</code></pre>
<p>On AWS, if a tool adds the same tags everywhere, configure it once in the provider instead of in every resource:</p>
<pre><code class="language-hcl">provider "aws" {
  region = "us-east-1"

  ignore_tags {
    keys         = ["LastBackup"]
    key_prefixes = ["scanner:"]
  }
}
</code></pre>
<h2>ignore_changes = all</h2>
<pre><code class="language-hcl">lifecycle {
  ignore_changes = all
}
</code></pre>
<p>This tells Terraform to create the resource and then never update it. It is occasionally useful for a resource you want created once and handed over to another team. For anything else it is a trap: the resource looks managed, appears in state, and silently stops matching your code.</p>
<h2>Common errors and limits</h2>
<p><strong>It can't be conditional.</strong> This fails:</p>
<pre><code class="language-hcl">lifecycle {
  ignore_changes = var.autoscaling ? [desired_count] : []   # not allowed
}
</code></pre>
<p><code>ignore_changes</code> only accepts static attribute names, not expressions or variables. If you need both behaviours, define two versions of the resource and pick one with <code>count</code>, or move the decision into separate modules.</p>
<p><strong>It can't be set from outside a module.</strong> A module caller cannot add <code>ignore_changes</code> to resources inside the module. The <code>lifecycle</code> block has to be in the module's own resource. If you maintain the module, expose the choice as two resource variants as above.</p>
<p><strong>The attribute name must exist.</strong> <code>ignore_changes = [desired_capacity]</code> on a resource that has no such attribute is an error. Check the provider docs for the exact name.</p>
<h2>How ignore_changes hides drift</h2>
<p>The problem starts when <code>ignore_changes</code> is added to silence a plan nobody understood:</p>
<ol>
<li>Someone opens port 22 on a security group in the console during an incident.</li>
<li>The next plan wants to remove the rule.</li>
<li>To get the deploy through, someone adds <code>ignore_changes = [ingress]</code>.</li>
<li>The port stays open, and no plan will ever mention it again.</li>
</ol>
<p>That's not a lifecycle rule; it's an unreviewed exception with no expiry. The same pattern shows up with IAM policies, bucket policies and encryption settings, exactly the attributes where a silent change matters most.</p>
<h2>How to use ignore_changes safely</h2>
<ul>
<li><strong>Write down why.</strong> Add a comment next to every <code>ignore_changes</code> saying which system owns the value. If nobody can name one, the rule probably shouldn't exist.</li>
<li><strong>Never ignore security attributes.</strong> Security group rules, IAM policies, bucket policies, encryption and public-access settings should be fixed in code, not ignored.</li>
<li><strong>Review the list.</strong> Search your code for <code>ignore_changes</code> every quarter. Each entry should still have an owner.</li>
<li><strong>Keep checking ignored attributes for drift.</strong> Because Terraform still records the real values in state, a scheduled check can compare them with what you expect. The <a href="https://www.orchesterra.in/glossary/how-to-detect-terraform-drift/">Terraform drift detection guide</a> shows how to run one, and <a href="https://www.orchesterra.in/blog/terraform-refresh-only/"><code>terraform plan -refresh-only</code></a> is the safest way to see what changed.</li>
<li><strong>Decide what to do with each drift finding:</strong> update the code, revert the change, or accept it with an expiry. The <a href="https://www.orchesterra.in/blog/iac-drift-triage-playbook/">drift triage playbook</a> covers the decision.</li>
</ul>
<h2>Guarding against hidden drift</h2>
<p>Two checks stop <code>ignore_changes</code> from quietly piling up.</p>
<p><strong>Fail CI on blanket ignores.</strong> <code>ignore_changes = all</code> and a bare <code>[tags]</code> are almost never what you want, and a one-line grep catches them:</p>
<pre><code class="language-bash">if grep -rnE 'ignore_changes[[:space:]]*=[[:space:]]*(all|\[[[:space:]]*tags[[:space:]]*\])' --include='*.tf' .; then
  echo "Blanket ignore_changes found. Ignore single attributes or tag keys instead." &gt;&amp;2
  exit 1
fi
</code></pre>
<p><strong>Treat every new</strong> <code>ignore_changes</code> <strong>as a review item.</strong> Any other new entry in a pull request is a new blind spot. The reviewer should see it and check that its comment names the owner.</p>
<h3>The ECS task_definition catch</h3>
<p>Ignoring <code>task_definition</code> on an <code>aws_ecs_service</code> works only while the service exists. If a change forces a replacement, the new service is created with the revision your code points at. That is usually an old one, so the replacement quietly redeploys stale code.</p>
<p>One fix is to read the live revision with a data source and point the service at whichever revision is newer:</p>
<pre><code class="language-hcl">data "aws_ecs_task_definition" "api" {
  task_definition = aws_ecs_task_definition.api.family
}

resource "aws_ecs_service" "api" {
  # ...
  task_definition = "${aws_ecs_task_definition.api.family}:${max(
    aws_ecs_task_definition.api.revision,
    data.aws_ecs_task_definition.api.revision,
  )}"
}
</code></pre>
<p>With that in place a replacement comes back on the revision the pipeline deployed, and you may not need to ignore <code>task_definition</code> at all.</p>
<p>Thanks to a reader on <a href="http://dev.to">dev.to</a> for raising both points.</p>
<h2>Where OrchesTerra fits</h2>
<p><code>ignore_changes</code> exists because teams need some way to deal with changes made outside Terraform. OrchesTerra handles those changes directly instead. It checks your AWS accounts against your Terraform on a schedule and ranks each difference by risk, so an extra tag ranks low and a port opened to the internet ranks high. Each finding goes through an approval: update the code, revert the change, or accept it with an expiry date. Nothing gets hidden permanently.</p>
<p>You can see it in the <a href="https://app.orchesterra.in/auth/login?demo=1&amp;utm_source=devto&amp;utm_medium=crosspost">read-only demo</a> without signing up.</p>
<p>To see what is still drifting after your <code>ignore_changes</code> rules, run a refresh-only check. The free, open-source <a href="https://github.com/orchesterra/cloud-drift-report">cloud-drift-report</a> CLI does that and ranks each change, so a security change that should never be ignored stands out.</p>
<h2>Quick checklist</h2>
<ul>
<li>Use <code>ignore_changes</code> only when another system owns the value on purpose.</li>
<li>Ignore single tag keys, not <code>tags</code>, and use the AWS provider's <code>ignore_tags</code> for tags added everywhere.</li>
<li>Avoid <code>ignore_changes = all</code> unless you mean "create once, then hand over".</li>
<li>Never use it to silence security changes; fix them in code.</li>
<li>Comment each entry with its owner, and review the list regularly.</li>
<li>Fail CI on <code>ignore_changes = all</code> or a bare <code>[tags]</code>, and review every new entry.</li>
<li>If you ignore an ECS <code>task_definition</code>, make sure a replacement deploys the live revision, not the one in code.</li>
</ul>
<p><em>Originally published on the</em> <a href="https://www.orchesterra.in/blog/terraform-ignore-changes/"><em>OrchesTerra blog</em></a><em>.</em></p>
]]></content:encoded></item></channel></rss>