<p>In Helm's v3 documentation: <a href="https://helm.sh/docs/chart_template_guide/accessing_files/" rel="nofollow noreferrer">Accessing Files Inside Templates</a>, the author gives an example of 3 properties (toml) files; where each file has only one key/value pair.</p>
<p>The configmap.yaml looks like this. I'm only adding one <em>config.toml</em> for simplicity.</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-config
data:
  {{- $files := .Files }}
  {{- range tuple &quot;config.toml&quot; }}
  {{ . }}: |-
    {{ $files.Get . }}
  {{- end }}
</code></pre>
<p>This works fine, until I add a <em>second</em> line to the config.toml file.</p>
<p>config.toml</p>
<pre><code>replicaCount=1
foo=bar
</code></pre>
<p>Then I get an Error: <code>INSTALLATION FAILED: YAML parse error on deploy/templates/configmap.yaml: error converting YAML to JSON: yaml: line 9: could not find expected ':'</code></p>
<p>Any thoughts will be appreciated.
Thanks</p>

<p>Helm will read in that file, but it is (for good or bad) a <strong>text</strong> templating engine. It does not understand that you are trying to compose a YAML file and thus it will not help you. That's actually why you will see so many, many templates in the wild with <code>{{ .thing | indent 8 }}</code> or <code>{{ .otherThing | toYaml }}</code> -- because <a href="https://helm.sh/docs/chart_template_guide/control_structures/#controlling-whitespace" rel="nofollow noreferrer">you need to help Helm</a> know in what context it is emitting the <em>text</em></p>
<p>Thus, in your specific case, you'll want the <a href="https://masterminds.github.io/sprig/strings.html#indent" rel="nofollow noreferrer"><code>indent</code> filter</a> with a value of 4 because your current template has two spaces for the key indent level, and two more spaces for the value block scalar</p>
<pre><code>data:
  {{- $files := .Files }}
  {{- range tuple &quot;config.toml&quot; }}
  {{ . }}: |-
{{ $files.Get . | indent 4 }}
{{/* notice this ^^^ template expression is flush left,
because the 'indent' is handling whitespace, not the golang template itself */}}
  {{- end }}
</code></pre>
<hr />
<p>Also, while this is the specific answer to your question, don't overlook the <a href="https://helm.sh/docs/chart_template_guide/accessing_files/#configmap-and-secrets-utility-functions" rel="nofollow noreferrer"><code>.AsConfig</code> section on that page</a> which seems much more likely to be what you really want to happen, and requires less <code>indent</code> math</p>
