<p>Given the following json:</p>

<pre><code>    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: {{ template "something.server.fullname" . }}
    data:
    {{ (.Files.Glob "dashboards/*.json").AsConfig | indent 2 }}
    {{ (.Files.Glob "datasources/*.json").AsConfig | indent 2 }}
</code></pre>

<p>How can I check if the folder exists and is not empty?</p>

<p>Currently, if the folder is missing or doesn't have any files, helm install will abort with this message:</p>

<pre><code>Error: YAML parse error on domething/charts/grafana/templates/dashboards-configmap.yaml: error converting YAML to JSON: yaml: line 6821: could not find expected ':'
</code></pre>

<p>You can pull your Globs out to variables, and then move everything within <code>if</code> blocks, e.g.:</p>

<pre><code>{{- $globdash := .Files.Glob "dashboards/*.json" }}
{{ if $globdash }}
{{- $globdata := .Files.Glob "datasources/*.json" }}
{{ if $globdata }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "something.server.fullname" . }}
data:
{{ ($globdash).AsConfig | indent 2 }}
{{ ($globdata).AsConfig | indent 2 }}
{{ end }}
{{ end }}
</code></pre>
