<p>i have a scenario,</p>
<p>How to fetch particular field value and also update particular field value?</p>
<p><strong>For example :</strong>
Im deploying an application using terraform &quot;kubernetes_deployment&quot; resource configured with environment variables(<strong>endpoint=abc</strong>) and <strong>replicas=2</strong>.</p>
<pre><code>resource &quot;kubernetes_deployment&quot; “app” {
…..….
spec {
  replicas = 2
  template {
    spec {
     ….
      env {
        name  = “ENDPOINT”
        value = “abc”
    }
}
</code></pre>
<p>Once i deployed using terraform script, another script might change configurations <strong>replicas=5</strong> and environment values(<strong>endpoint=xyz</strong>)</p>
<p>Now i need to update only replicas to 20(if replicas &lt; 20) through terraform script without changing the environment values(endpoint=abc)?</p>
<pre><code>resource &quot;kubernetes_deployment&quot; “app” {
…..….
spec {
  replicas = 20       -&gt; only this has to reflect in apply
  template {
    spec {
     ….
      env {
        name  = “ENDPOINT”
        value = “abc”
    }
}
</code></pre>
<p>How can i fetch particular field(replicas) to compare if replicas count &gt; 20 and update only replicas count?</p>
<p>Can someone with more Terraform experience help me on this?</p>

Prakash26790
<p>Inside the &quot;kubernetes_deployment&quot; resource block, consider adding a lifecycle block. Use it to ignore changes to resource attributes that can be made outside of Terraform's knowledge.</p>
<p>Provide a list of resource attributes to &quot;ignore_changes&quot;, which Terrform would ignore in subsequent runs. The arguments are the relative address of the attributes in the resource. Map and list elements can be referenced using index notation.</p>
<pre><code>lifecycle {
    ignore_changes = [spec[&quot;env&quot;]]
  }
</code></pre>
<p>Reference: <a href="https://www.terraform.io/docs/language/meta-arguments/lifecycle.html#ignore_changes" rel="nofollow noreferrer">https://www.terraform.io/docs/language/meta-arguments/lifecycle.html#ignore_changes</a></p>
