<p>I m trying to inject env vars in my helm chart deployment file. my values file looks like this.</p>
<p>values.yaml</p>
<pre><code>envFrom:
  - configMapRef:
      name: my-config
  - secretRef: 
      name: my-secret
</code></pre>
<p>I want to iterate through secrets and configmaps values . This is what I did in deployment.yaml file</p>
<pre><code>  envFrom:
       {{- range  $item := .Values.envFrom }}
      
          {{- $item | toYaml | nindent 14 }}
       {{- end }}
</code></pre>
<p>But i didn t get the desired result</p>

nada809
<p>You can directly use the defined value like:</p>
<pre class="lang-yaml prettyprint-override"><code>...
      envFrom:
      {{- toYaml .Values.envFrom | nindent 6 }}
...
</code></pre>
<hr />
<p>Or Instead of use range, you can use <a href="https://helm.sh/docs/chart_template_guide/control_structures/#modifying-scope-using-with" rel="nofollow noreferrer">with</a>.<br>
Here is an example:</p>
<p><code>values.yaml</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>envFrom:
  - configMapRef:
      name: my-config
  - secretRef: 
      name: my-secret
</code></pre>
<p><code>pod.yaml</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
  namespace: test
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, &quot;env&quot; ]
      # {{- with .Values.envFrom }} can be here if you dont
      # want to define envFrom in this container if envFrom
      # is not defined in values.yaml.
      # If you want to do that, remove the one below.
     {{- with .Values.envFrom }}
      envFrom:
        {{- toYaml . | nindent 8 }}
      {{- end }}
  restartPolicy: Never
</code></pre>
<p>The output is:</p>
<pre class="lang-yaml prettyprint-override"><code>c[_] &gt; helm template test .
---
# Source: test/templates/test.yaml
apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
  namespace: test
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, &quot;env&quot; ]
      envFrom:
        - configMapRef:
            name: my-config
        - secretRef:
            name: my-secret
  restartPolicy: Never
</code></pre>
