<p>I am working with helm.</p>

<p>I have a condtion where a variable in values.yaml ( variable name is db) will get conditional value (either oracle or postgres).</p>

<p>In the same values.yaml i have two sections containing respective properties for oracle &amp; postgres.</p>

<p>How can I use the variable in db in nested manner? I want to avoid if else blocks.</p>

<p>I tried {{tpl .Values.{{tpl .Values.db .}}.port .}}. but it doesn't work.</p>

<p>Please find below code snippet  </p>

<p>Values.yaml</p>

<pre><code>db: postgres
postgres:
  port:5432
oracle:
  port:1521
</code></pre>

<p>templatefile.yaml</p>

<pre><code>port: "{{tpl .Values.{{tpl .Values.db .}}.port .}}"
</code></pre>

Arshad
<p>You can't nest the <code>{{ ... }}</code> blocks in the Helm templating language.</p>

<p>You can set a variable to the value of the inner "template" or just invoke it directly as an expression</p>

<pre><code>{{- $dbname := tpl .Values.db . -}}
{{- printf "%s" (tpl .Values.db .) -}}
</code></pre>

<p>To actually use this as a field in the <code>.Values</code> structure, you need the <a href="https://godoc.org/text/template" rel="nofollow noreferrer">text/template</a> <code>index</code> function.</p>

<pre><code>{{- $settings := index .Values (tpl .Values.db .) -}}
port: "{{ $settings.port }}"
</code></pre>
