<p>Given a yaml file (helmfile) like the following</p>

<pre><code>releases:
  - chart: ../charts/foo
    name: foo
    namespace: '{{ .Values.stack }}'
    values:
      - ../config/templates/foo-values.yaml.gotmpl
    set:
      - name: image.tag
        value: 22
      - name: replicas
        value: 1
  - chart: ../charts/bar
    name: bar
    namespace: '{{ .Values.stack }}'
    values:
      - ../config/templates/bar-values.yaml.gotmpl
    set:
      - name: image.bar_proxy.tag
        value: 46
      - name: image.bar.tag
        value: 29
      - name: replicas
        value: 1
</code></pre>

<p>I'm trying to figure out a clean way to update a specific image tag. For example, I'd like to update <code>image.bar_proxy.tag</code> from <code>46</code> to <code>51</code>.</p>

<p>I have the following, which does the job, but it requires that you know the exact index of the array item:</p>

<pre><code>yq -y '.releases[] |= if .name=="bar" then .set[0].value |= 51 else . end' helmfile-example.yaml
</code></pre>

<p>So if the array order were to change at some point this would break.</p>

<p>A preferred solution would be: "update image.bar_proxy.tag value from <code>46</code> to <code>51</code> where set[].name==image.bar_proxy.tag". Any ideas on how to achieve a more specific conditional selection like this?</p>

<p>FYI our yq version:</p>

<pre><code>$ yq --version
yq 2.10.0
</code></pre>

<p>You can use the following filter to make it work. It works by dynamically selecting the index of the object where your tag exists. On the selected object <code>.value=51</code> will update the value as you wanted. You can also use the <code>-i</code> flag to do in-place modification of the original file.</p>

<pre><code>yq -y '.releases[].set |= map(select(.name == "image.bar_proxy.tag").value=51)' yaml
</code></pre>

<p>See the underlying <code>jq</code> filter acting on the JSON object at <a href="https://jqplay.org/s/lOYEE1IyQd" rel="noreferrer">jq-playground</a></p>
