<p>I am working on a problem to implement a helm chart with customize configMap and trying to populate the configMap based on the environment mode.</p>
<p>Values.yaml</p>
<pre><code>externalIPService:
 ip: 1.1.1.1
 port:  80 

emsConfig: &quot;receivers:
 otlp:
   protocols:
     http:
processors:
 batch:
exporters:
 otlp/ems:
   endpoint: {{ .Values.externalIPService.ip }}:{{ .Values.externalIPService.port }}
service:
 pipelines:
   traces:
     receivers: [otlp]
     processors: [batch]
     exporters: [otlp/ems]
   metrics:
     receivers: [otlp]
     processors: [batch]
     exporters: [otlp/ems]
   logs:
     receivers: [otlp]
     processors: [batch]
     exporters: [otlp/ems]
&quot;
</code></pre>
<p>configMap.yaml</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: simple-demo
data:
  message: &quot;{{ tpl .Values.emsConfig .}}&quot;
</code></pre>
<p>The helm template output is a plain string and not a yaml content. I have tried <em>toYaml</em> as well but it did not help either. Could someone please help to find a way to do nested rendering and to be able to use the final output in the confiMap</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: simple-demo
data:
  message: &quot;receivers: otlp: protocols: http: processors: batch: exporters: otlp/ems: endpoint: {{ .Values.externalIPService.ip }}:{{ .Values.externalIPService.port }} service: pipelines: traces: receivers: [otlp] processors: [batch] exporters: [otlp/ems] metrics: receivers: [otlp] processors: [batch] exporters: [otlp/ems] logs: receivers: [otlp] processors: [batch] exporters: [otlp/ems] &quot;
</code></pre>

sks
<p>in this situation, you need to use <code>_halpers.tpl</code> file.</p>
<p>first, add this to the <code>_halpers.tpl</code> file:</p>
<pre><code>{{- define &quot;appname.emsConfig&quot; -}}
receivers:
 otlp:
   protocols:
     http:
processors:
 batch:
exporters:
 otlp/ems:
   endpoint: {{ .Values.externalIPService.ip }}:{{ .Values.externalIPService.port }}
service:
 pipelines:
   traces:
     receivers: [otlp]
     processors: [batch]
     exporters: [otlp/ems]
   metrics:
     receivers: [otlp]
     processors: [batch]
     exporters: [otlp/ems]
   logs:
     receivers: [otlp]
     processors: [batch]
     exporters: [otlp/ems]
{{- end }}
</code></pre>
<p>the <code>values.yaml</code> file will look like this:</p>
<pre><code>externalIPService:
 ip: 1.1.1.1
 port:  80 

</code></pre>
<p>and the <code>configMap.yaml</code> file, will need to look like this:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: simple-demo
data:
  message: |-
  {{ include &quot;appname.emsConfig&quot; . | nindent 4}}
</code></pre>
