<p>I want to loop over a secret file I'm generating in my ci pipeline.</p>

<pre><code>helm template \
  ...
  --set-file secretmap="secretmap.yaml" \
  ...
</code></pre>

<p>The <code>secretmap.yaml</code> is generated and contains the following:</p>

<pre><code>SEC_1: 111
SEC_2: 222
...
</code></pre>

<p>The secret.yaml looks like this:</p>

<pre><code>kind: Secret
...
data:
{{- range $key, $val := .Values.secretmap }}
  {{ $key }}: {{ $val | b64enc | quote }}
{{- end }}
...
</code></pre>

<p>And the error I get is:</p>

<pre><code>Error: render error in ".../secret.yaml": template: .../secret.yaml:4:31: ... range can't iterate over SEC_1: 111
SEC_1: 222
...
</code></pre>

<p>The same configuration does work with configmap though,<br>
where I set the configmap from <code>-f chart/values/common.yaml</code></p>

natdev
<p><code>--set-file</code> sets the contents of the variable to the text contents of the file; it doesn’t try to interpret it at all.  (Somewhat described in <a href="https://helm.sh/docs/using_helm/#customizing-the-chart-before-installing" rel="nofollow noreferrer">this section of the Helm docs</a>; note the example there is a JavaScript script being embedded in a ConfigMap.)  That means you need to tell Helm to parse the file.  Helm includes a minimally-documented <a href="https://github.com/helm/helm/blob/main/pkg/engine/funcs.go#L98" rel="nofollow noreferrer"><code>fromYaml</code></a> function that can do this.</p>
<p>When you iterate through the contents of the value, try explicitly parsing it first:</p>
<pre><code>{{- range $key, $val := fromYaml .Values.secretmap }}
...
{{ end }}
</code></pre>
