<p>I have a template that creates a <code>configMap</code> from the <code>jmeter-test-data-file-configmap.yaml</code> file in helm chart:</p>
<pre><code>{{- if .Values.env.datafile }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: jmeter-testdata
data:
  {{ .Values.env.datafile }}: |-
  {{ .Files.Get .Values.env.datafile | indent 4}}
{{- end }}
</code></pre>
<p>the corresponding yaml.configuration is:</p>
<pre><code>env:
  testfile: sample
  datafile: example.csv
</code></pre>
<p>When I do the <code>helm upgrade</code>, everything is ok, if the example.csv is a single line text file like that:</p>
<pre><code>1,1
</code></pre>
<p>but is it would have at least two or even more lines</p>
<pre><code>1,1
2,2
</code></pre>
<p>the deployment fails with unrelated error message:</p>
<pre><code>upgrade.go:123: [debug] preparing upgrade for jmeter
Error: UPGRADE FAILED: YAML parse error on jmeter/templates/jmeter-test-data-file-configmap.yaml: error converting YAML to JSON: yaml: line 7: did not find expected key
helm.go:81: [debug] error converting YAML to JSON: yaml: line 7: did not find expected key
YAML parse error on jmeter/templates/jmeter-test-data-file-configmap.yaml
</code></pre>
<p>and the debug details are:</p>
<pre><code>helm.sh/helm/v3/pkg/releaseutil.(*manifestFile).sort
        /home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:146
helm.sh/helm/v3/pkg/releaseutil.SortManifests
        /home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:106
helm.sh/helm/v3/pkg/action.(*Configuration).renderResources
        /home/circleci/helm.sh/helm/pkg/action/action.go:165
helm.sh/helm/v3/pkg/action.(*Upgrade).prepareUpgrade
        /home/circleci/helm.sh/helm/pkg/action/upgrade.go:215
helm.sh/helm/v3/pkg/action.(*Upgrade).Run
        /home/circleci/helm.sh/helm/pkg/action/upgrade.go:124
main.newUpgradeCmd.func2
        /home/circleci/helm.sh/helm/cmd/helm/upgrade.go:155
github.com/spf13/cobra.(*Command).execute
        /go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:850
github.com/spf13/cobra.(*Command).ExecuteC
        /go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:958
github.com/spf13/cobra.(*Command).Execute
        /go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:895
main.main
        /home/circleci/helm.sh/helm/cmd/helm/helm.go:80
runtime.main
        /usr/local/go/src/runtime/proc.go:204
runtime.goexit
        /usr/local/go/src/runtime/asm_amd64.s:1374
UPGRADE FAILED
main.newUpgradeCmd.func2
        /home/circleci/helm.sh/helm/cmd/helm/upgrade.go:157
github.com/spf13/cobra.(*Command).execute
        /go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:850
github.com/spf13/cobra.(*Command).ExecuteC
        /go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:958
github.com/spf13/cobra.(*Command).Execute
        /go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:895
main.main
        /home/circleci/helm.sh/helm/cmd/helm/helm.go:80
runtime.main
        /usr/local/go/src/runtime/proc.go:204
runtime.goexit
</code></pre>
<p>So, the error points to this line:</p>
<pre><code>  {{ .Values.env.datafile }}: |-
</code></pre>
<p>What could be wrong here and how can the file itself hurt the template processing because of its new lines? We tired /r/n, /n, /r with no success, all the same</p>
<p>We also tried to hadcode the line:7 like that:</p>
<pre><code>{{- if .Values.env.datafile }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: jmeter-testdata
data:
  example.csv: |-
  {{ .Files.Get .Values.env.datafile | indent 4}}
{{- end }}
</code></pre>
<p>and still the same error. And even to replace the template value with the hardcode:</p>
<pre><code>{{- if .Values.env.datafile }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: jmeter-testdata
data:
  {{ (printf &quot;example.csv&quot; ) }}: |-
  {{ .Files.Get (printf &quot;example.csv&quot; ) | indent 4}}
{{- end }}
</code></pre>
<p>But still the same error.</p>
<p>And that doesn't happens with almost the same config, that bring the multiline xml file to the configMap exactly the same way:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: jmeter-test
data:
  test.jmx: |-
{{ .Files.Get (printf &quot;%s.jmx&quot; .Values.env.testfile ) | indent 4}}
</code></pre>
<p>I suppose, that for some reason, probaby the intend is't applied to all lines for csv file, when it is applied to the jmx file. But how to figure that out ad how to work it around?</p>
<p>UPD:</p>
<pre><code>1, 1
    2, 2
    3, 3
</code></pre>
<p>&quot;intending&quot; files manually like above made the trick, it was deployed, however this file isn't ok to use for the needs then. How to avoid that?</p>

Eljah
<p>If you have a line containing <code>indent</code> it probably needs to begin at the start of the line, even if it's in otherwise indented context.</p>
<pre class="lang-yaml prettyprint-override"><code>{{- if .Values.env.datafile }}
...
data:
  {{ .Values.env.datafile }}: |-
{{ .Files.Get .Values.env.datafile | indent 4}}
{{/*- previous line is not indented */}}
{{- end }}
</code></pre>
<p>In your original example, let's focus on these two lines:</p>
<pre class="lang-yaml prettyprint-override"><code>  {{ .Values.env.datafile }}: |-
  {{ .Files.Get .Values.env.datafile | indent 4}}
## (these two spaces are important)
</code></pre>
<p>Now, if the input line is your second example</p>
<pre class="lang-none prettyprint-override"><code>1,1
2,2
</code></pre>
<p>Now: the line containing <code>indent 4</code> is itself indented by 2 spaces.  So in that line you have the two spaces at the start of the line, plus the four spaces from <code>indent 4</code>, so 6 spaces; then a newline and four spaces from <code>indent 4</code>, but no start-of-line spaces (you're still in the output from <code>indent</code>), so only 4 spaces.</p>
<pre class="lang-yaml prettyprint-override"><code>  test.jmx: |-
      1,1
    2,2
</code></pre>
<p>If you run <code>helm template --debug</code> on your original chart, you will still get the YAML parsing error, but it should also print out this output.</p>
<p>In some contexts you may find it slightly more aesthetic to use <code>nindent</code>, which includes a newline before the first line's indentation, in combination with a <code>-</code> just inside the curly braces to consume the preceding whitespace (including both spaces and newlines).  This should also work:</p>
<pre class="lang-yaml prettyprint-override"><code>data:
  {{ .Values.env.datafile }}: |-
  {{- .Files.Get .Values.env.datafile | nindent 4}}
  {{/*- indented, starts with -, uses nindent */}}
</code></pre>
<p>But also for example:</p>
<pre class="lang-yaml prettyprint-override"><code>metadata:
  labels: {{- include &quot;common.labels&quot; . | nindent 4 }}
  annotations: {{- include &quot;common.annotations&quot; . | nindent 4 }}
</code></pre>
