<p>The following command is messy, but works just fine:</p>
<pre class="lang-yaml prettyprint-override"><code>dict(
&quot;resources&quot; (ternary $args.resources (ternary $.Values.machines.micro (ternary $.Values.machines.small (ternary $.Values.machines.medium $.Values.machines.large (eq $args.machine &quot;medium&quot;)) (eq $args.machine &quot;small&quot;)) (eq $args.machine &quot;micro&quot;)) (eq $args.machine nil))
)
</code></pre>
<p>The following 2 fail:</p>
<pre class="lang-yaml prettyprint-override"><code>&quot;resources&quot; (ternary $args.resources (index $.Values.machines $args.machine) (eq $args.machine nil))
&quot;resources&quot; (ternary $args.resources (get $.Values.machines $args.machine) (eq $args.machine nil))
</code></pre>
<p>With 2 respective errors:</p>
<pre><code># index
Error: template: tensor-etl-sol-chart/templates/template_deploys.yaml:65:40: executing &quot;tensor-etl-sol-chart/templates/template_deploys.yaml&quot; at &lt;index $.Values.machines $args.machine&gt;: error calling index: value is nil; should be of type string

# get
Error: template: tensor-etl-sol-chart/templates/template_deploys.yaml:65:67: executing &quot;tensor-etl-sol-chart/templates/template_deploys.yaml&quot; at &lt;$args.machine&gt;: wrong type for value; expected string; got interface {}
</code></pre>
<p>Why? And how to make it work?</p>
<p>Values.yaml:</p>
<pre class="lang-yaml prettyprint-override"><code>machines:
  micro:
    cpu: &quot;250m&quot;
    memory: &quot;500Mi&quot;
  small:
    cpu: &quot;500m&quot;
    memory: &quot;1400Mi&quot;
  medium:
    cpu: &quot;1000m&quot;
    memory: &quot;3200Mi&quot;
  large:
    cpu: &quot;1500m&quot;
    memory: &quot;6900Mi&quot;

...

  - name: 'inflate-bad-tmeta'
#    machine: small #&lt;--- want to be able to uncomment this line, and should fallback to &quot;resources&quot; on the next lnie
    resources:
      cpu: '888m'
      memory: '888Mi'
</code></pre>

ilmoi
<p>As best I can tell, you'd want <code>|default</code> to make the <code>index</code> structure intact when they don't specify a <code>machine:</code> key at all, and then a separate <code>| default</code> for falling back to the inlined <code>resources:</code> block on bogus machine reference (as will be the case for both a missing <code>machine:</code> key as well as one that doesn't exist)</p>
<pre class="lang-yaml prettyprint-override"><code># templates/debug.yaml
data:
  example: |
    {{ range .Values.things }}
    machine {{ .name }} is
    {{ (index 
      $.Values.machines
      (.machine | default &quot;nope&quot;) 
      ) | default .resources }}
    {{ end }}
</code></pre>
<p>then, given</p>
<pre class="lang-yaml prettyprint-override"><code>machines:
  micro:
    cpu: &quot;250m&quot;
    memory: &quot;500Mi&quot;
  small:
    cpu: &quot;500m&quot;
    memory: &quot;1400Mi&quot;
  medium:
    cpu: &quot;1000m&quot;
    memory: &quot;3200Mi&quot;
  large:
    cpu: &quot;1500m&quot;
    memory: &quot;6900Mi&quot;

things:
  - name: 'inflate-bad-tmeta'
#    machine: small #&lt;--- want to be able to uncomment this line, and should fallback to &quot;resources&quot; on the next lnie
    resources:
      cpu: '888m'
      memory: '888Mi'
</code></pre>
<p>it says</p>
<pre><code>    machine inflate-bad-tmeta is
    map[cpu:888m memory:888Mi]
</code></pre>
<p>but given</p>
<pre class="lang-yaml prettyprint-override"><code>things:
  - name: 'inflate-bad-tmeta'
    machine: small
    resources:
      cpu: '888m'
      memory: '888Mi'
</code></pre>
<p>it says</p>
<pre><code>    machine inflate-bad-tmeta is
    map[cpu:500m memory:1400Mi]
</code></pre>
<p>at your discretion whether you'd want to actually <code>fail</code> if <em>both</em> things are set, since it can cause the consumer to think their <code>resources:</code> win</p>
