<p>I am creating a config map as below</p>
<p><code>kubectl create configmap testconfigmap --from-file=testkey=/var/opt/testfile.txt</code></p>
<p>As I am using helm charts, I would like to create the config map using YAML file instead of running kubectl.
I went through <a href="https://stackoverflow.com/questions/53429486/kubernetes-how-to-define-configmap-built-using-a-file-in-a-yaml">Kubernetes - How to define ConfigMap built using a file in a yaml?</a> and we can use <code>.Files.Get</code> to access the files.
But then testfile.txt needs to be a part of helm. I would like to have something like</p>
<pre><code>kind: ConfigMap
metadata:
  name: testconfigmap
data:
  fromfile: |-
{{ .Files.Get &quot;/var/opt/testfile.txt&quot; | indent 4 }}
</code></pre>
<p>It works when &quot;testfile.txt&quot; is under the main helm directory. So, <code>{{ .Files.Get &quot;testfile.txt&quot; | indent 4 }}</code> works but <code>{{ .Files.Get &quot;/var/opt/testfile.txt&quot; | indent 4 }}</code> doesn't. With custom path, the value for the ConfigMap is empty.</p>
<p>Is is possible to place the file at a custom path outside the helm folder, so I can define my path in Values.yaml and read it in my ConfigMap yaml ?</p>

<p><em>This is a Community Wiki answer so feel free to edit it and add any additional details you consider important.</em></p>
<p>As <a href="https://stackoverflow.com/users/225016/mdaniel">mdaniel</a> has already stated in his comment:</p>
<blockquote>
<p><em>Is is possible to place the file at a custom path outside the helm
folder</em> no, because <a href="https://helm.sh/docs/chart_template_guide/accessing_files/" rel="noreferrer">helm considers that a security risk</a> – mdaniel 2
days ago</p>
</blockquote>
<p>You can also compare it with <a href="https://github.com/helm/helm/issues/3276" rel="noreferrer">this</a> feature request on <strong>GitHub</strong> where you can find very similar requirement described in short e.g. in <a href="https://github.com/helm/helm/issues/3276#issuecomment-353675624" rel="noreferrer">this comment</a>:</p>
<blockquote>
<p>I have this exact need. My chart publishes a secret read from file at
/keybase. This file is deliberately not in the chart.</p>
<p>I believe files for .Files.Get should not be assumed to be inside the
chart ...</p>
</blockquote>
<p>One interesting <a href="https://github.com/helm/helm/issues/3276#issuecomment-353718344" rel="noreferrer">comment</a>:</p>
<blockquote>
<p>lenalebt commented on Dec 23, 2017 I am quite sure .<code>Files.Get</code> not
being able to access the file system arbitrarily is a security
feature, so I don't think the current behaviour is wrong - it just
does not fulfill all use cases.</p>
</blockquote>
<p>This issue was created quite long time ago (Dec 19, 2017) but has been recently reopened. There are even <a href="https://github.com/helm/helm/issues/3276#issuecomment-607952569" rel="noreferrer">some specific proposals on how it could be handled</a>:</p>
<blockquote>
<p>titou10titou10 commented on Apr 2 @misberner can you confirm that
using--include-dir =will allow us to use
.Files.Glob().AsConfig(), and so create a ConfigMap with one
entry in the CM per file in?</p>
<p>@misberner misberner commented on Apr 2 Yeah that's the idea. An open
question from my point of view is whether an --include-dir with a
specified  introduces an overlay, or shadows everything under
/ from previous args and from the bundle itself. I'm not super
opinionated on that one but would prefer the former.</p>
</blockquote>
<p>The most recent comments give some hope that this feature might become available in future releases of helm.</p>
