<p>I have a few yaml files that contains some values. I want to read that files while helm deploying and create configmaps for each of them.</p>
<p>I've added config file under the helm charts. ( Same level with templates folder )</p>
<p><a href="https://i.stack.imgur.com/kGOni.png" rel="nofollow noreferrer">chart structure</a></p>
<p>And then I've tried to create 'configmap-creator.yaml' which is located under the 'templates' folder.</p>
<p>I simply run 'helm upgrade --install ealpkar --namespace ealpkar --create-namespace .'
It was complete successfully but there is only one configmap which is called 'config2-configmap'. I missed the first one ( config1-configmap )</p>
<p>Here is the 'configmap-creator.yaml'</p>
<pre><code>{{- $files := .Files }}
{{- range $key, $value := .Files }}
{{- if hasPrefix &quot;config/&quot; $key }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $key | trimPrefix &quot;config/&quot; | replace &quot;.yaml&quot; &quot;&quot; | replace &quot;_&quot; &quot;-&quot; }}-configmap
data:
{{ $key | trimPrefix &quot;config/&quot; }}: {{ $files.Get $key | quote }}
{{- end }}
{{- end }}
</code></pre>
<p>Example of yaml file  which is under 'config' folder;</p>
<ul>
<li><p>config1.yaml</p>
<pre><code>dummy_product:
  ip: 10.10.10.10
  port: 22
</code></pre>
</li>
<li><p>config2.yaml</p>
<pre><code>dummy_product_2:
  ip: 10.10.10.20
  port: 22
</code></pre>
</li>
</ul>

<p>Fix your template, adding a separator between objects.</p>
<pre><code>{{- $files := .Files }}
{{- range $key, $value := .Files }}
{{- if hasPrefix &quot;config/&quot; $key }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $key | trimPrefix &quot;config/&quot; | replace &quot;.yaml&quot; &quot;&quot; | replace &quot;_&quot; &quot;-&quot; }}-configmap
data:
  {{ $key | trimPrefix &quot;config/&quot; }}: {{ $files.Get $key | quote }}
{{- end }}
{{- end }}
</code></pre>
