Helm Interpolation

Viewed 2451

I am setting the following environment variable in Helm Deployment like so.

name: SERVER_ENDPOINT
value: {{ .Values.server.dev_proxy_endpoint }}

But would like to interpolate the environment part (dev) of the value variable, like so

name: SERVER_ENDPOINT
value: {{ .Values.server. {{ .Values.environment | lower }} _proxy_endpoint }}

Is this possible?

Reply to first comment

I tried that out by creating a new definition at the top of the file like so:

{{- $value_path_to_endpoint := print ".Values.server." .Values.environment  "_proxy_endpoint" -}}

But that then presents a literal value, rather than the context pointer to the values file.

name: SERVER_ENDPOINT
value: {{ $value_path_to_endpoint}}

In other words, $value_path_to_endpoint returns:

".Values.server.dev_proxy_endpoint"

Rather than

.Values.server.dev_proxy_endpoint
2 Answers

You can use index function from Go text/template and Helm's printf function

env:
- name: SERVER_ENDPOINT
  value: {{ (index .Values.server (printf "%s_proxy_endpoint" ( .Values.environment | lower ))) }}
Related