<p>Im in a bit of a pickle on how to get a File templated.</p>

<p>I have a Secret template defined</p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: "awx-secrets"
type: Opaque
data:
  confd_contents: &lt;value-is-an-entire-file&gt;
</code></pre>

<p>Now the file <code>credentials.py</code> that is supposed to be value to the key <code>confd_contents</code> looks like</p>

<pre><code>DATABASES = {
    'default': {
        'ATOMIC_REQUESTS': True,
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': "{{ .Values.dbDatabaseName }}",
        'USER': "{{ .Values.dbUser }}",
        'PASSWORD': "{{ .Values.dbPassword }}",
        'HOST': "{{ .Values.dbHostname }}",
        'PORT': "{{ .Values.dbService.port }}",
    }
}
</code></pre>

<p>As you can see, there are values in this file aswell which are defined in my <code>values.yaml</code> file.</p>

<p>Now I want to make sure that the file <code>credentials.py</code> is rendered with the right values and is then passed on to the Secret and that the secret is rendered correctly.</p>

<p>I tried to define it as a File object by doing this :</p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: "awx-secrets"
type: Opaque
data:
  confd_contents: {{ .Files.Get "files/credentials.py" }}
</code></pre>

<p>But this does not work. If I try to template it, I get the actual variables names :</p>

<pre><code>helm template management 

apiVersion: v1
kind: Secret
metadata:
  name: "awx-secrets"
type: Opaque
data:
  confd_contents: DATABASES = {
    'default': {
        'ATOMIC_REQUESTS': True,
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': "{{ .Values.dbDatabaseName }}",
        'USER': "{{ .Values.dbUser }}",
        'PASSWORD': "{{ .Values.dbPassword }}",
        'HOST': "{{ .Values.dbHostname }}",
        'PORT': "{{ .Values.dbService.port }}",
    }
}
</code></pre>

<p>I also tried to put the whole file in my secret template. Something like</p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: "awx-secrets"
type: Opaque
data:
  confd_contents: DATABASES = {
    'default': {
        'ATOMIC_REQUESTS': True,
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': "{{ .Values.dbDatabaseName }}",
        'USER': "{{ .Values.dbUser }}",
        'PASSWORD': "{{ .Values.dbPassword }}",
        'HOST': "{{ .Values.dbHostname }}",
        'PORT': "{{ .Values.dbService.port }}",
    }
}
</code></pre>

<p>When I run <code>helm template management</code>, it renders correctly but when I do a <code>helm install</code>, I get the error :</p>

<pre><code>error: error parsing test.yaml: error converting YAML to JSON: yaml: line 8: mapping values are not allowed in this context
</code></pre>

<p>Any idea what Im doing wrong or what might help ? </p>

<p>Solved this by </p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: "awx-secrets"
type: Opaque
data:
    confd_contents: {{ (tpl (.Files.Get "files/credentials.py") . | quote ) }}
</code></pre>
