<p>Try renaming values.yaml to values.yaml.j2 (jinja2) and remove the &quot;tpl&quot;, the template should just be as follows.</p>
<pre><code>  configMapKeyRef:
    name: {{ .Values.myConfigMapName }}
    key: application_port
</code></pre>
<p>I know that works with bazel builds using the following:</p>
<p><code>load(&quot;//build/helmcharts:helpers.bzl&quot;, &quot;release_chart&quot;)</code></p>

CC BY-SA 4.0
2021-12-23T19:52:53.513Z
2021-12-23T19:52:53.513Z
crusty-dave
<p>In the values.yaml we have the below env values and they are refered by <code>templates/deployment.yaml {{- toYaml .Values.env | nindent 12 }}</code></p>
<pre><code>env:
  - name: APPLICATION_PORT
    valueFrom:
      configMapKeyRef:
        name: application-properties
        key: application_port
  - name: POSTGRES_AUTH_URL
    valueFrom:
      configMapKeyRef:
        name: application-properties
        key: postgres_business_auth_url
  - name: POSTGRES_DATA_URL
    valueFrom:
      configMapKeyRef:
        name: application-properties
        key: postgres_verification_data_url
</code></pre>
<p>Trying to change the above and make a template of the ConfigMap name without any success, by receiving the following error:</p>
<p><code>cannot load values.yaml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{&quot;tpl .Values.myConfigMapName .&quot;:interface {}(nil)}</code></p>
<pre><code>myConfigMapName: application-properties

env:
  - name: APPLICATION_PORT
    valueFrom:
      configMapKeyRef:
        name: {{ tpl .Values.myConfigMapName . }}
        key: application_port
  - name: POSTGRES_AUTH_URL
    valueFrom:
      configMapKeyRef:
        name: {{ tpl .Values.myConfigMapName . }}
        key: postgres_business_auth_url
  - name: POSTGRES_DATA_URL
    valueFrom:
      configMapKeyRef:
        name: {{ tpl .Values.myConfigMapName . }}
        key: postgres_verification_data_url
</code></pre>
<p>How can I consume a variable from values.yaml and use it within values.yaml ?</p>

CC BY-SA 4.0
2021-12-21T23:48:08.553Z
The values file is only values, there's no templating support in that file. But you can run templates against a value in templates where you use the values.
BMitch
<helm>
Helm how to use variables in values.yaml
igiannak
# Helm how to use variables in values.yaml

(Asked by: username_0 on 2021-12-21)

In the values.yaml we have the below env values and they are refered by templates/deployment.yaml {{- toYaml .Values.env | nindent 12 }}
env:
  - name: APPLICATION_PORT
    valueFrom:
      configMapKeyRef:
        name: application-properties
        key: application_port
  - name: POSTGRES_AUTH_URL
    valueFrom:
      configMapKeyRef:
        name: application-properties
        key: postgres_business_auth_url
  - name: POSTGRES_DATA_URL
    valueFrom:
      configMapKeyRef:
        name: application-properties
        key: postgres_verification_data_url

Trying to change the above and make a template of the ConfigMap name without any success, by receiving the following error:
cannot load values.yaml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{"tpl .Values.myConfigMapName .":interface {}(nil)}
myConfigMapName: application-properties

env:
  - name: APPLICATION_PORT
    valueFrom:
      configMapKeyRef:
        name: {{ tpl .Values.myConfigMapName . }}
        key: application_port
  - name: POSTGRES_AUTH_URL
    valueFrom:
      configMapKeyRef:
        name: {{ tpl .Values.myConfigMapName . }}
        key: postgres_business_auth_url
  - name: POSTGRES_DATA_URL
    valueFrom:
      configMapKeyRef:
        name: {{ tpl .Values.myConfigMapName . }}
        key: postgres_verification_data_url

How can I consume a variable from values.yaml and use it within values.yaml ?

**Tags:** helm

> **Comments:**
> **username_1**: The values file is only values, there's no templating support in that file. But you can run templates against a value in templates where you use the values.  

---

## 1 answers

### Answer by username_2 on 2021-12-23. Score: -2

Try renaming values.yaml to values.yaml.j2 (jinja2) and remove the "tpl", the template should just be as follows.
  configMapKeyRef:
    name: {{ .Values.myConfigMapName }}
    key: application_port

I know that works with bazel builds using the following:
load("//build/helmcharts:helpers.bzl", "release_chart")


---

