<p>I am trying to use <code>if/else-if/else</code> loop in helm chart. Basically, I want to add ENV configs in configfile based on the if/else condition. Below is the logic:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Values.applicationName }}-configmap
  labels:
    projectName: {{ .Values.applicationName }}
    environment: {{ .Values.environment }}
    type: configmap
data:
{{- if eq .Values.environment &quot;production&quot; }}
{{ .Files.Get &quot;config-prod.yaml&quot; | nindent 2}}
{{- else if eq .Values.environment &quot;development&quot; }}
{{ .Files.Get &quot;config-dev.yaml&quot; | nindent 2}}
{{- else }}
{{ .Files.Get &quot;config-stage.yaml&quot; | nindent 2}}
{{- end }}

</code></pre>
<p>But I am not getting the desired output and facing some issue. Can anybody help me out with this?</p>
<p>Edit1: I have added my modified configmap.yaml as per the suggestions, helm install/template command gives <code>Error: YAML parse error on demo2/templates/configmap.yaml: error converting YAML to JSON: yaml: line 14: did not find expected key </code>error.</p>
<p>also my config-prod and config-stage is being rendered (as per the condition if I give <code>environment: production</code> then config-prod.yaml is being added and if I give <code>environment: stage/null</code> then config-stage.yaml is being added.</p>

dharmendra kariya
<p>Your question would benefit from more specifics.</p>
<p>Please consider adding the following to your question:</p>
<ul>
<li>How are you trying this? What commands exactly did you run?</li>
<li>How are you &quot;not getting the desired output&quot;? What output did you get?</li>
</ul>
<p>Please also include:</p>
<ul>
<li>the relevant entries from your <code>values.yaml</code></li>
<li>the <code>config-dev.yaml</code> and <code>config-stage.yaml</code> files</li>
</ul>
<p>Have you run <a href="https://helm.sh/docs/helm/helm_template/" rel="nofollow noreferrer">helm template</a> to generate the templates that Helm would apply to your cluster? This would be a good way to diagnose the issue.</p>
<p>I wonder whether you're chomping too much whitespace.</p>
<p>And you should just chomp left, i.e. <code>{{- .... }}</code> rather than left+right <code>{{- ... -}}</code>.</p>
