3

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
Theo Sweeny
  • 1,033
  • 14
  • 26

2 Answers2

3

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 ))) }}
edbighead
  • 5,607
  • 5
  • 29
  • 35
0

I had a quick look around, and it looks like that this is possible. This article here explains how a few other people have achieved the same :)

Kubernetes Helm, combine two variables with a string in the middle

Sweet Chilly Philly
  • 3,014
  • 2
  • 27
  • 37