<p>I have a helm 3 template with the following yaml which works perfectly fine. It has a multi-line shell script as part of the <code>initContainers</code> and it works as needed.</p>

<pre><code>  initContainers:
  - name: check-crd
    image: 'bitnami/kubectl:1.12'
    env:
      - name: CRDs
        value: {{ .Values.CRDs.list }}
    command:
    - "/bin/bash"
    - "-c"
    - |
      set -x
      for i in $(echo $CRDs | tr ":" "\n")
      do 
        kubectl get -o json $i
      done
</code></pre>

<p>However, when I try to move the shell script into a helm value I get an error. The new yaml and the values:</p>

<pre><code>  initContainers:
  - name: check-crd
    image: 'bitnami/kubectl:1.12'
    env:
      - name: CRDs
        value: {{ .Values.CRDs.list }}
    command:
    - "/bin/bash"
    - "-c"
    - {{ .Values.CRDs.script }}
</code></pre>

<p>the <code>values.yaml</code> file is:</p>

<pre><code>CRDs:
  list: 'mycrd1s.example.com:mycrd2s.example.com'
  script: |
          set -x
          for i in $(echo $CRDs | tr ":" "\n")
          do 
            kubectl get -o json $i
          done
</code></pre>

<p>When I try to helm3 install this, I get an error:</p>

<pre><code> error converting YAML to JSON: yaml: line 30: could not find expected ':'
</code></pre>

<p>I understand that this is some kind of YAML multi-line string issue but could not understand how to fix this. I have tried with various combinations of <code>{{</code>, <code>{{-</code>, <code>toYaml</code> etc. but could not resolve this issue. Any way to make use of a multi-line shell script as a helm value ?</p>

<p>PS: I understand that I can create a <code>ConfigMap</code> with the shell script as the data and achieve the same, but I want everything to be done just via the yaml files, because I cannot create a configmap for some unavoidable reason.</p>

<p>You need to add nindent, like following</p>

<pre><code>        initContainers:
        - name: check-crd
          image: 'bitnami/kubectl:1.12'
          env:
          - name: CRDs
            value: {{ .Values.CRDs.list }}
          command:
          - "/bin/bash"
          - "-c"
          - {{- toYaml .Values.CRDs.script | nindent 12 }}
</code></pre>
