<p>Context:
I'm reusing <code>terraform</code> modules and I deploy microservices using <code>helm</code> provider within terraform.</p>
<p>Problem:</p>
<p>I'm trying to translate this line into terraform code, to get the current image tag live from prod (in the interest of reusing it). I'm already using kubernetes provider's auth and doesn't make sense to pull kubectl in my CI just for this.</p>
<p><code>k get deploy my-deployment -n staging -o jsonpath='{$.spec.template.spec.containers[:1].image}'</code></p>
<p>Kubernetes terraform provider doesn't seem to support <code>data</code> blocks nor helm provider <code>outputs</code> blocks.</p>
<p>Does anyone know how could we get (read) the image tag of a deployment using terraform?</p>
<p>EDIT:</p>
<p>My deployment looks like this:</p>
<pre><code>resource &quot;helm_release&quot; &quot;example&quot; {
  name       = &quot;my-redis-release&quot;
  repository = &quot;https://charts.bitnami.com/bitnami&quot;
  chart      = &quot;redis&quot;
  version    = &quot;6.0.1&quot;

  values = [
    &quot;${file(&quot;values.yaml&quot;)}&quot;
  ]

  set {
    name  = &quot;image.tag&quot;
    value = &quot;latest&quot;
  }

}

</code></pre>
<p>The tag will be a hash that will change often and passed on from another repo.</p>
<p><code>latest</code> in this case should be replaced by the current running tag in the cluster. I can get it using kubectl, using the line above, but not sure how using terraform.</p>

mattmin
<p>It turns out there are multiple ways of doing it, where the easiest one for me is to reference the <code>set</code> argument of the <code>helm_release</code> resource:</p>
<pre><code>output &quot;helm_image_tag&quot; {
  value = [ for setting in helm_release.example.set : setting.value if setting.name == &quot;image.tag&quot; ]
}
</code></pre>
<p>The output will then be a list where you can reference it in a shell script (or another scripting language):</p>
<pre><code>  + helm_image_tag = [
      + &quot;latest&quot;,
    ]
</code></pre>
<p>If the list format does not suit you, you can create a map output:</p>
<pre><code>output &quot;helm_image_tag&quot; {
value = { for setting in helm_release.example.set : setting.name =&gt; setting.value if setting.name == &quot;image.tag&quot; }
}
</code></pre>
<p>This produces the following output:</p>
<pre><code>  + helm_image_tag = {
      + &quot;image.tag&quot; = &quot;latest&quot;
    }
</code></pre>
<p>By using <code>terraform output helm_image_tag</code> you can access this output value and decide what to do with it in the CI.</p>
