<p>I am trying to access a helm value dynamically though another variable as I am utilizing the range functionality to create multiple deployments. Take for example this section of my deployment file</p>
<pre><code>{{- range $teams := .Values.teams }}
.
.
.
        ports:
        - containerPort: {{ .Values.deployment.backend.($teams.tag).serverPort }}
          protocol: {{ .Values.deployment.backend.($teams.tag).serverProtocol }}
        - containerPort: {{ .Values.deployment.backend.($teams.tag).authPort }}
          protocol: {{ .Values.deployment.backend.($teams.tag).authProtocol }}

.
.
.
---
{{- end }}

</code></pre>
<p>with a values.yml file of</p>
<pre><code>teams:
  - name: TeamA
    tag: teamA
  - name: TeamB
    tag: teamB
  - name: TeamC
    tag: teamC
deployment:
  backend:
    teamA:
      serverPort: 10001
      serverProtocol: TCP
      authPort: 10010
      authProtocol: TCP
    teamB:
      serverPort: 9101
      serverProtocol: TCP
      authPort: 9110
      authProtocol: TCP
    teamC:
      serverPort: 9001
      serverProtocol: TCP
      authPort: 9010
      authProtocol: TCP


</code></pre>
<p>I am not able to figure out how to pass $teams.tag to be evaluated to return the overall value of containerPort for example.</p>
<p>Any help is appreciated.</p>
<p>Cheers</p>

<p>Helm itself provides a number of functions for you to manipulate the value.</p>
<p>Here is one way to handle the your use case with <code>get</code> function.</p>
<pre><code>{{- $ := . -}}
{{- range $teams := .Values.teams }}
.
.
.
        ports:
        - containerPort: {{ (get $.Values.deployment.backend $teams.tag).serverPort }}
          protocol: {{ (get $.Values.deployment.backend $teams.tag).serverProtocol }}
        - containerPort: {{ (get $.Values.deployment.backend $teams.tag).authPort }}
          protocol: {{ (get $.Values.deployment.backend $teams.tag).authProtocol }}

.
.
.
---
{{- end }}
</code></pre>
<p>Please be noted that the scope inside the <code>range</code> operator will change. So, you need to preassign the <code>.</code> to <code>$</code> in order to access the root scope.</p>
<p>You can also refer to this doc, <a href="https://helm.sh/docs/chart_template_guide/function_list/" rel="nofollow noreferrer">https://helm.sh/docs/chart_template_guide/function_list/</a>, to know more about the funcitons you can use.</p>
