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?
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
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 ))) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With