<p>I am using Helm to deploy to a Kubernetes cluster. I have researched configmaps and found it is possible to retrieve data from a file and put it into the configmap.</p>
<p>I have the following <code>configmap.yaml</code>:</p>
<pre><code>kind: ConfigMap 
apiVersion: v1 
metadata:
  name: {{ .Values.app.configMap }}
  namespace: {{ .Values.app.namespace }}
data:
    config.json: |-
      {{ .Files.Glob &quot;my-config.json&quot; | indent 2}}
</code></pre>
<p>and my <code>deployment.yaml</code> contains the relevant volumeMount (if I put actual json data directly into configmap.yaml then the config deploys). My <code>configmap.yaml</code> and <code>deployment.yaml</code> are both kept in /chart/templates but I keep <code>my-config.json</code> within the base helm chart directory, outside of the <code>templates</code> folder.</p>
<p>When I try deploying with the chart, I get the following error:</p>
<pre><code>Error: template: chart/templates/configmap.yaml:8:54: executing &quot;chart/templates/configmap.yaml&quot; at &lt;2&gt;: wrong type for value; expected string; got engine.files
</code></pre>
<p>How can I use the <code>.json</code> file in my configmap without putting the raw json data directly into the yaml file?</p>

Lucy
<p>The <code>.Files</code> object is described in the Helm <a href="https://helm.sh/docs/chart_template_guide/builtin_objects/" rel="noreferrer">Built-in Objects</a> documentation.  <code>.Files.Glob</code> returns a list of files matching some pattern, like <code>*.json</code>; you probably want <code>.Files.Get</code> instead to return the file content.</p>
<p>YAML is also very sensitive to whitespace handling and indentation.  When you do retrieve the file, you probably want that line to start at the first column, but then call the <code>indent</code> function with some number more than the indent level of the previous line.  This also indents the first line, and you can double-check with <code>helm template</code> that the right thing came out.</p>
<pre class="lang-yaml prettyprint-override"><code>data:
  {{-/* Note, indent of only two spaces */}}
  config.json: |-
{{ .Files.Get &quot;my-config.json&quot; | indent 4 }}
{{/* .Get, not .Glob; indent 4 spaces, more than 2 above */}}
</code></pre>
