<p>I want to create a helm chart that results in a config map that looks like this:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfigmap
data:
  myconfigfile1.properties: |
    property11 = value11
    property12 = value12
  myconfigfile1.properties: |
    property21 = value21
    property22 = value22
</code></pre>

<p>whereas this part shall be configurable in the <code>values.yaml</code>:</p>

<pre><code>myconfig:
  myconfigfile1.properties: |
    property11 = value11
    property12 = value12
  myconfigfile1.properties: |
    property21 = value21
    property22 = value22
</code></pre>

<p>Now I want to iterate over all the children of <code>myconfig</code> in the <code>values.yaml</code> and add them to my helm template. My attempts so far with this template:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfigmap
data: 
  # {{- range $key, $val := .Values.myconfig}}
  # {{ $key }}: |
  #   {{ $val }}
  # {{- end }}

</code></pre>

<p>resulted in this error message:</p>

<pre><code>$ helm install --dry-run --debug ./mychart/ --generate-name
install.go:159: [debug] Original chart version: ""
install.go:176: [debug] CHART PATH: /home/my/helmcharts/mychart
Error: YAML parse error on mychart/templates/myconfig.yaml: error converting YAML to JSON: yaml: line 11: could not find expected ':'
helm.go:84: [debug] error converting YAML to JSON: yaml: line 11: could not find expected ':'
YAML parse error on mychart/templates/myconfig.yaml
</code></pre>

<p>I can avoid the error by removing the <code>|</code> after <code>myconfigfile1.properties:</code> in my <code>values.yaml</code>, however then I lose the line breaks and the result is not what I want.</p>

<p>Many thanks for your help in advance.</p>

<p>Kind regards,
Martin</p>

<p>A few minutes after writing this question I stubled upon <a href="https://stackoverflow.com/questions/62432632/convert-a-yaml-to-string-in-helm">Question #62432632 convert-a-yaml-to-string-in-helm</a> which does not exactly answer my question but with its help I could find the correct syntax.</p>

<p><code>values.yaml</code>:</p>

<pre><code>myconfig:
  myconfigfile1.properties: |-
    property11 = value11
    property12 = value12

  myconfigfile2.properties: |-
    property21 = value21
    property22 = value22
</code></pre>

<p>template:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfigmap
data: 
{{- range $name, $config := .Values.myconfig }}
  {{ $name }}: |-
{{ tpl $config $ | indent 4 }}
  {{- end }}

</code></pre>
