<p>I have a configMap file:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    owner: testdb
  name: testdb-configmap 
data:
  host: postgres
  port: &quot;5432&quot; 

</code></pre>
<p>and a secret file:</p>
<pre><code>aapiVersion: v1
kind: Secret
type: Opaque
metadata:
  labels:
    owner: testdb
  name: testdb-secret
  namespace: test
data:
  user: dGVzdA==
  pwd: dGVzdA==
</code></pre>
<p>and I want to build an environment variable <code>CONNECTION_STRING</code> as below:</p>
<pre><code>env:
 - name: CONNECTION_STRING
   value: &quot;Host=&lt;host-from-configmap&gt;;Username=&lt;user-from-secret&gt;;Password=&lt;password-from-secret&gt;;Port=&lt;port-from-configmap&gt;;Pooling=False;&quot;
</code></pre>
<p>I want to know if this is possible and if yes, then how? I have also looked at using <code>.tpl</code> (named templates) but couldn't figure out a way.</p>
<hr />
<p><strong>NOTE</strong></p>
<p>Since I don't have access to the image which requires <code>CONNECTION_STRING</code> I have to build it this way. These configmap and secret files are also going to remain like this.</p>
<hr />

Alpesh
<p>Kubernetes can <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#using-environment-variables-inside-of-your-config" rel="nofollow noreferrer">set environment variables based on other environment variables</a>.  This is a core Kubernetes Pod capability, and doesn't depend on anything from Helm.</p>
<p>Your value uses four components, two from the ConfigMap and two from the Secret.  You need to declare each of these as separate environment variables, and then declare a main environment variable that concatenates them together.</p>
<pre class="lang-yaml prettyprint-override"><code>env:
  - name: TESTDB_HOST
    valueFrom:
      configMapKeyRef:
        name: testdb-configmap # {{ include &quot;chart.name&quot; . }}
        key: host
  - name: TESTDB_PORT
    valueFrom:
      configMapKeyRef:
        name: testdb-configmap
        key: port
  - name: TESTDB_USER
    valueFrom:
      secretKeyRef:
        name: testdb-secret
        key: user
  - name: TESTDB_PASSWORD
    valueFrom:
      secretKeyRef:
        name: testdb-secret
        key: password
  - name: CONNECTION_STRING
    value: Host=$(TESTDB_HOST);Username=$(TESTDB_USER);Password=$(TESTDB_PASSWORD);PORT=$(TESTDB_PORT);Pooling=False;
</code></pre>
