<p>I'm trying to check if a value is true or not, but for every variation that I try, the error below is always shown:</p>
<pre><code>_helpers.tpl:96:19: executing &quot;mongo_databasename&quot; at &lt;.Values.mongo.enabled&gt;: can't evaluate field Values in type string
</code></pre>
<p>Part of my _helpers.tpl file:</p>
<pre><code>{{/*
Get mongodb connection string
*/}}
{{- define &quot;mongo_databasename&quot; -}}
{{-  if eq (.Values.mongo.enabled | toString) &quot;true&quot; }}
{{-  .Values.mongo.databaseName }}
{{- else }}
{{-  .Values.environmentVars.mongo.databaseName }}
{{- end -}}
{{- end -}}
</code></pre>
<p>The respective part of my values.yaml file:</p>
<pre><code>mongo:
  enabled:
  username: user
</code></pre>
<p>I've tried many ways to check the if condition, like the one above:</p>
<pre><code>{{-  if .Values.mongo.enabled  }}
</code></pre>

mayconfsbrito
<p>It may be caused by the scope of include.</p>
<p>The template looks okay.</p>
<p>I tried as follows</p>
<p>_helper.tpl</p>
<pre class="lang-yaml prettyprint-override"><code>{{/*
Get mongodb connection string
*/}}
{{- define &quot;mongo_databasename&quot; -}}
{{- if .Values.mongo.enabled }}
{{- .Values.mongo.databaseName }}
{{- else }}
{{- .Values.environmentVars.mongo.databaseName }}
{{- end -}}
{{- end -}}
</code></pre>
<p>values.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>mongo:
  enabled:
  username: user
  databaseName: test

environmentVars:
  mongo:
    databaseName: envvar
</code></pre>
<p>templates/configmap.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include &quot;test.fullname&quot; . }}
data:
  test: {{- include &quot;mongo_databasename&quot; .}}
  test2:
    {{- with .Values.mongo }}
    {{- include &quot;mongo_databasename&quot; $ }}
    {{- end }}
</code></pre>
<p>output</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: test-v7
data:
  test:envvar
  test2:envvar
</code></pre>
<p>Pay attention to the scope (<code>. | $</code>) passed in at the end of the <code>templates/configmap.yaml include</code> statement.</p>
