Answers: <p>This is how I ended up solving it</p>
  <pre><code>apiVersion: v1
  kind: ConfigMap
  metadata:
    name: app-cm
  data:
    app.properties: |-
      {{- tpl ($.Files.Get &quot;conf/app.properties.tmpl&quot;) . | nindent 4 }}
  
    app-users.properties: |-
      {{- tpl ($.Files.Get &quot;conf/app-users.properties.tmpl&quot;) . | nindent 4 }}
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2023-12-05T10:10:01.633Z
Answers: 2023-12-05T10:10:01.633Z
Answers: Nifle
Answers: <p>Try with <code>Files.Glob</code> , <code>Files.AsConfig</code> and with indentation. Similar pattern works for me -&gt;</p>
  <pre><code>apiVersion: v1
  kind: ConfigMap
  metadata:
    name: example1
  data:
  {{ (.Files.Glob &quot;conf/my-large-file1.conf&quot;).AsConfig | indent 2 }}
  </code></pre>
  <p><code>Files.Glob</code> - <a href="https://helm.sh/docs/chart_template_guide/accessing_files/#glob-patterns" rel="nofollow noreferrer">reference</a></p>
  <p><code>AsConfig</code> - <a href="https://helm.sh/docs/chart_template_guide/builtin_objects/#:%7E:text=Files.AsConfig%20is%20a%20function%20that%20returns%20file%20bodies%20as%20a%20YAML%20map." rel="nofollow noreferrer">reference</a>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-10-19T10:18:45.010Z
Answers: 2023-10-19T10:18:45.010Z
Answers: devcodes
Body: <p>I have a helm deployment that includes a configmap.<br />
  I would like to add a few rather large files to it and I thought I coud put them in a an external directory</p>
  <pre><code>my-app/values.yaml
  my-app/conf/my-large-file1.conf
  my-app/conf/my-large-file2.conf
  my-app/templates/configmaps.yaml
  </code></pre>
  <p>I thought I could use include but this did not work</p>
  <pre><code>---
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: example1
  data:
    index.html: {{ include &quot;/conf/my-large-file1.conf&quot; . }}
  </code></pre>
  <p>Error:</p>
  <pre><code>template: my-app/templates/configmaps.yaml:23:17: executing &quot;my-app/templates/configmaps.yaml&quot; at &lt;include &quot;/conf/my-large-file1.conf&quot; .&gt;: error calling include: template: no template &quot;/conf/my-large-file1.conf&quot; associated with tem\
      plate &quot;gotpl&quot;
  </code></pre>
  <p>I then tried different things with  <code>{{ $.Files.Get &quot;conf/my-large-file1.conf&quot; }}</code> but got weird scoping errors.</p>
  <p>So my hope is that someone can tell me how to do it correctly</p>
  <pre><code>$ helm version
  version.BuildInfo{Version:&quot;v3.11.1+6.el8&quot;, GitCommit:&quot;66bfc44f827aea6eb8e001150914170ac0d49e2d&quot;, GitTreeState:&quot;clean&quot;, GoVersion:&quot;go1.18.9&quot;}
  </code></pre>
  
Tags: <helm>
Title: How do I include a file in a helm config map
UserDisplayName: Nifle
ThreadText: # How do I include a file in a helm config map
  
  (Asked by: username_0 on 2023-10-04)
  
  I have a helm deployment that includes a configmap.  
  I would like to add a few rather large files to it and I thought I coud put them in a an external directory
  
  ```
  my-app/values.yaml
  my-app/conf/my-large-file1.conf
  my-app/conf/my-large-file2.conf
  my-app/templates/configmaps.yaml
  
  ```
  
  I thought I could use include but this did not work
  
  ```
  ---
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: example1
  data:
    index.html: {{ include "/conf/my-large-file1.conf" . }}
  
  ```
  
  Error:
  
  ```
  template: my-app/templates/configmaps.yaml:23:17: executing "my-app/templates/configmaps.yaml" at <include "/conf/my-large-file1.conf" .>: error calling include: template: no template "/conf/my-large-file1.conf" associated with tem\
      plate "gotpl"
  
  ```
  
  I then tried different things with `{{ $.Files.Get "conf/my-large-file1.conf" }}` but got weird scoping errors.
  
  So my hope is that someone can tell me how to do it correctly
  
  ```
  $ helm version
  version.BuildInfo{Version:"v3.11.1+6.el8", GitCommit:"66bfc44f827aea6eb8e001150914170ac0d49e2d", GitTreeState:"clean", GoVersion:"go1.18.9"}
  
  ```
  
  **Tags:** helm
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2023-12-05. Score: 0 | Accepted answer
  
  This is how I ended up solving it
  
  ```
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: app-cm
  data:
    app.properties: |-
      {{- tpl ($.Files.Get "conf/app.properties.tmpl") . | nindent 4 }}
  
    app-users.properties: |-
      {{- tpl ($.Files.Get "conf/app-users.properties.tmpl") . | nindent 4 }}
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2023-10-19. Score: 2
  
  Try with `Files.Glob` , `Files.AsConfig` and with indentation. Similar pattern works for me ->
  
  ```
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: example1
  data:
  {{ (.Files.Glob "conf/my-large-file1.conf").AsConfig | indent 2 }}
  
  ```
  
  `Files.Glob` - [reference](https://helm.sh/docs/chart_template_guide/accessing_files/#glob-patterns)
  
  `AsConfig` - [reference](https://helm.sh/docs/chart_template_guide/builtin_objects/#:%7E:text=Files.AsConfig%20is%20a%20function%20that%20returns%20file%20bodies%20as%20a%20YAML%20map.).
  
  
  ---
  
  