<p>I am creating a github actions step</p>
<pre><code>.
.
.
steps:
  name: export-secrets
  run: |
    echo '${{ toJSON(secrets) }}' &gt;&gt; gh-secrets.json
.
.
.
</code></pre>
<p>suppose the gh-secrets.json file is as below:</p>
<pre><code># gh-secrets.json
{&quot;A&quot;: &quot;a1&quot;, &quot;B&quot;: &quot;b1&quot;, &quot;C&quot;: &quot;c1&quot;}
</code></pre>
<p>Then I am going to pull the helm charts and untar them and then move <code>gh-secrets.json</code> into the untar directory. The reason I am doing this is according to <a href="https://helm.sh/docs/chart_template_guide/accessing_files/" rel="nofollow noreferrer">helm docs</a>, &quot;Files outside of a helm application subchart, including those of the parent, cannot be accessed&quot;</p>
<p>suppose I have these files in the untar directory</p>
<pre><code># values.yaml
secrets:
  - A
  - B
</code></pre>
<p>and I have <code>templates/secrets.yaml</code>:</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: {{ .Release.Name }}-secret
data:
    {{- range .Values.secrtes }}
      {{ . }}: {{ $.Files.Get &quot;gh-secrets.json&quot; | toJson }}
    {{- end }}
</code></pre>
<p>this is the result:</p>
<pre><code># Source: mktplc-catalog/templates/secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: release-name-secret
data:
      A: &quot;'{\&quot;A\&quot;: \&quot;a1\&quot;, \&quot;B\&quot;: \&quot;b1\&quot;, \&quot;C\&quot;: \&quot;c1\&quot;}'&quot;
      B: &quot;'{\&quot;A\&quot;: \&quot;a1\&quot;, \&quot;B\&quot;: \&quot;b1\&quot;, \&quot;C\&quot;: \&quot;c1\&quot;}'&quot;

</code></pre>
<p>but I want it to be</p>
<pre><code># Source: mktplc-catalog/templates/secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: release-name-secret
data:
      A: &quot;a1&quot;
      B: &quot;b1&quot;
</code></pre>
<p>How can I achieve this?</p>

<p>Helm includes a <a href="https://docs.helm.sh/docs/chart_template_guide/function_list/#fromjson" rel="nofollow noreferrer"><code>fromJson</code></a> function; in fact, its documentation fairly closely matches your updated setup.  So you can use this to read in the file, parse it, and then select the specific key out of it.</p>
<pre class="lang-yaml prettyprint-override"><code>data:
{{- $secrets := .Files.Get &quot;gh-secrets.json&quot; | fromJson -}}
{{- range .Values.secrets }}
  {{ . }}: {{ index $secrets . }}
{{- end }}
</code></pre>
<p>You appear to have some control over the input structure here.  If you can wrap the secret values in some top-level key</p>
<pre class="lang-bash prettyprint-override"><code>echo '{&quot;secretValues&quot;: ${{ toJSON(secrets) }}}' &gt; gh-secrets.json
</code></pre>
<p>then you can provide this as an extra values file to Helm (valid JSON files are also valid YAML)</p>
<pre class="lang-bash prettyprint-override"><code>helm install -f gh-secrets.json ...
</code></pre>
<p>This file doesn't need to be in the chart directory.  Now Helm will parse it for you, and it will be available as <code>.Values.secretValues</code> matching the injected key.  (Remember that the <code>range</code> loop resets the value of <code>.</code>, so you will need to save its value outside the loop.)</p>
<p>If this technique works for you, it might be possible to use it to directly inject the secret values without the layer of indirection; use something like</p>
<pre class="lang-yaml prettyprint-override"><code>data:
{{ .Values.secretValues | toYaml | indent 2 }}
</code></pre>
