<p>I'm migrating from Docker to Helm3. My Docker deployment uses .env files to load environment variables see <a href="https://docs.docker.com/compose/env-file/" rel="nofollow noreferrer">reference</a>. During the migration I need to support both the old way and new way so I don't want change the .env format if I can avoid it.</p>
<p>Here's my sample .env file:</p>
<pre><code>key1=value1
key2=value2
</code></pre>
<p>Then in my Helm3 deployment.yaml I need:</p>
<pre><code>kind: Deployment
spec:
  template:
    spec:
      containers:
          env:
            - name: key1
              value: &quot;value1&quot;
            - name: key2
              value: &quot;value2&quot;
</code></pre>
<p>The .env file is the helm project root directory so I'm hoping I can do something like this based on this <a href="https://stackoverflow.com/questions/63897532/use-helm-to-loop-thru-lines-of-dotenv-file-and-render-as-key-value-pair-in-confi">question</a> but not sure how to proceed:</p>
<pre><code>  {{- $files := .Files }}
  #Not sure how to select just one file?
  {{- range tuple &quot;.env&quot; }}
  
      #Split file by newlines and =
      {{- range $line := splitList &quot;\n&quot; $files.Get . }}
        {{/* Break the line into words */}}
        {{- $kv := splitList &quot;=&quot; $line -}}
        {{- $k := first $kv -}}
        {{ $k }}: {{ last $kv | quote }}
      {{- end }}

  {{- end }}
</code></pre>

<p>Here's what worked for me but I'm open to a better answer.
The only things I don't understand is why I need the empty line {{&quot;&quot;}} - I thought new lines would have been inserted without that.</p>
<p>The issue I had with the answer from @Matt was that the indentation came out wrong.</p>
<pre><code>{{ $file := .Files.Get &quot;.env&quot; | trimSuffix &quot;\n&quot; }}
{{- range $line := splitList &quot;\n&quot; $file -}}
{{- $kv := splitList &quot;=&quot; $line -}}
    {{ &quot;&quot; }}
    - name: {{ first $kv }}
      value: {{ last $kv | quote }}
{{- end }}
</code></pre>
