0

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 ?

igiannak
  • 220
  • 2
  • 11
  • 2
    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 Dec 21 '21 at 23:48

1 Answers1

-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")