<p>Im new at helm. Im building a splunk helm chart with numerous conf files. I currently  use something like this in a configmap ..</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: splunk-master-configmap
data:
  indexes.conf: |
    # global settings
    # Inheritable by all indexes: no hot/warm bucket can exceed 1 TB.
    # Individual indexes can override this setting.
    homePath.maxDataSizeMB = 1000000
</code></pre>
<p>but I would prefer to have the conf files in a seperate folder e.g. configs/helloworld.conf and have come accross &quot;tpl&quot; but am struggling to understand how to implement it. - can anyone advise best practices. On a side note splunk has orders of presidences &gt;&gt; so there may be many indexes.conf files used in various locations. does anyone have any thoughts on how best to implement this?!??!</p>
<p>Cheers.</p>

<p>If the content of the files is static then you could create a files directory in your chart at the same level as the templates directory (<a href="https://github.com/Activiti/activiti-cloud-charts/tree/master/activiti-keycloak" rel="noreferrer">not inside it</a>) and reference them like:</p>

<pre><code>kind: ConfigMap
metadata:
  name: splunk-master-configmap
data:
  {{ (.Files.Glob "files/indexes.conf").AsConfig | indent 2 }}
  {{ (.Files.Glob "files/otherfile.conf").AsConfig | indent 2 }}
# ... and so on
</code></pre>

<p>Where this would break down is if you want to be able to reference the values of variables inside the files so that the content is controlled from the values.yaml. If you want to expose each value individually then there's an <a href="https://github.com/technosophos/k8s-helm/blob/master/docs/chart_template_guide/variables.md" rel="noreferrer">example in the helm documentation using range</a>. But I think a good fit or your case is <a href="https://github.com/helm/charts/blob/31279766845d297d12bc4309177f46548b15f82b/stable/mysql/templates/configurationFiles-configmap.yaml" rel="noreferrer">what the stable/mysql chart does</a>. It has a ConfigMap that takes values as strings:</p>

<pre><code>{{- if .Values.configurationFiles }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "mysql.fullname" . }}-configuration
data:
{{- range $key, $val := .Values.configurationFiles }}
  {{ $key }}: |-
{{ $val | indent 4}}
{{- end }}
{{- end -}}
</code></pre>

<p>And the values.yaml allows both the files and their content to be set and overridden by the user of the chart:</p>

<pre><code># Custom mysql configuration files used to override default mysql settings
configurationFiles:
#  mysql.cnf: |-
#    [mysqld]
#    skip-name-resolve
#    ssl-ca=/ssl/ca.pem
#    ssl-cert=/ssl/server-cert.pem
#    ssl-key=/ssl/server-key.pem
</code></pre>

<p>It comments out that content and leaves it to the user of the chart to set but you could have defaults in the values.yaml.</p>

<p>You would only need <code>tpl</code> if you needed further flexibility. The <a href="https://github.com/helm/charts/tree/master/stable/keycloak" rel="noreferrer">stable/keycloak chart</a> lets the user of the chart create their own configmap and <a href="https://github.com/helm/charts/pull/6090#issuecomment-396941423" rel="noreferrer">point it into the keycloak deployment via tpl</a>. But I think your case is probably closest to the mysql one. </p>

<p>Edit: the tpl function can also be used to take the content of files loaded with Files.Get and effectively make that content part of the template - see <a href="https://stackoverflow.com/questions/47595295/how-do-i-load-multiple-templated-config-files-into-a-helm-chart/52009992#52009992">How do I load multiple templated config files into a helm chart?</a> if you're interested in this</p>
