<p>I'm trying to dynamically specify the name of a file to include in a configmap.yaml, using the Helm templating language.</p>

<p>Here is an example:</p>

<pre><code>{{- $filename := .Values.KRB5_REALM -}}
apiVersion: v1
data:
  # When the config map is mounted as a volume, these will be created as files.
  krb5.conf: |
{{ .Files.Get $filename".krb5.conf" | indent 4 }}
kind: ConfigMap
metadata:
  name: {{ template "myapp.fullname" . }}
  labels:
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version }}
    app: {{ template "myapp.name" . }}
    environment: {{ .Values.environment }}
</code></pre>

<p>The above code results in an error.</p>

<p>I've tried several variations but without any success, such as:</p>

<pre><code>{{ .Files.Get .Values.KRB5_REALM".krb5.conf" | indent 4 }}
</code></pre>

<p>How can I resolve this issue?</p>

<p>The usual way to assemble strings like this is with the <a href="https://godoc.org/text/template" rel="noreferrer">Go text/template</a> <code>printf</code> function.  One way to do it could be:</p>

<pre><code>{{ printf "%s.krb5.conf" .Values.KRB5_REALM | .Files.Get | indent 4 }}
</code></pre>

<p>Or you could parenthesize the expression:</p>

<pre><code>{{ .Files.Get (printf "%s.krb5.conf" .Values.KRB5_REALM) | indent 4 }}
</code></pre>
