I have an helm chart used to deploy an application that have configuration file in YAML format. Currently, my helm chart use the following code:
values.yaml
databaseUser: "dbuser"
configFiles:
db_config_file.yaml: |-
databaseUser: {{ .Values.databaseUser }}
databasePort: 1234
[...]
[...]
templates/configmap.yaml
data:
{{- range $name, $config := .Values.configFiles }}
{{ $name }}: |-
{{ tpl $config $ | indent 4 }}
{{- end }}
This code allow me to change easily the databaseUser
from values, but the problem is that if I want to change the value of databasePort
, I have to rewrite the entire configuration like that:
configFiles:
db_config_file.yaml: |-
databaseUser: {{ .Values.databaseUser }}
databasePort: 9876
which is inconvenient. It works like that because the db_config_file.yaml
content is interpreted as string because I give it to the tpl
function which only accept strings.
So my question is, is there a way to convert the YAML to string in a Helm template and get the following things:
databaseUser: "dbuser"
configFiles:
db_config_file.yaml: # Content is not a string block
databaseUser: {{ .Values.databaseUser }}
databasePort: 1234
[...]
[...]
data:
{{- range $name, $config := .Values.configFiles }}
{{ $name }}: |-
{{ tpl (<a toString function> $config) $ | indent 4 }}
{{- end }}
tpl
so the final solution was{{ tpl (toYaml .Values.configFiles.db_config_file_yaml ) . | indent 4 }}
– Guelders