<p>My goal is to convert values in Values.yaml into the following:</p>
<pre><code>CUSTOM_VARIABLE: &quot;TEST_ENV_1=devil,TEST_ENV_2=god,TEST_ENV_3=angel&quot;
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>### Values.yaml
env:
  TEST_ENV_1: devil
  TEST_ENV_2: god
  TEST_ENV_3: angel
</code></pre>
<p>The below template almost does this but I'm getting comma at the end: <code>TEST_ENV_1=devil,TEST_ENV_2=god,TEST_ENV_3=angel,</code>.</p>
<pre class="lang-yaml prettyprint-override"><code>### _envVars.tpl
{{ define &quot;envVars&quot; }}

...

- name: CUSTOM_VARIABLE
  value: &quot;
  {{- range $key, $value := .Values.env -}}
  {{- printf &quot;%s=%s,&quot; $key $value -}}
  {{- end -}}
  &quot; 

...

{{- end }}
</code></pre>
<p>Is there a way to apply template function (e.g. <code>trunc</code> to remove last symbol) to a range result in my case?</p>

<p>If you write the <code>range</code> call into a helper template, Helm has an <a href="https://docs.helm.sh/docs/chart_template_guide/named_templates/#the-include-function" rel="nofollow noreferrer"><code>include</code> extension function</a> that calls a template and captures its output as a string.</p>
<pre class="lang-yaml prettyprint-override"><code>{{/* Render the map-type template parameter to a key=value,key=value,
     list, ending with a trailing comma. */}}
{{- define &quot;custom.variable.format&quot; -}}
{{- range $key, $value := . -}}
{{ $key }}={{ $value }},
{{- end -}}
{{- end -}}

- name: CUSTOM_VARIABLE
  value: {{ include &quot;custom.variable.format&quot; .Values.env | trimSuffix &quot;,&quot; | quote }}
</code></pre>
<p>(It is probably cleaner to not generate the comma at all, as <a href="https://stackoverflow.com/a/68772574">@HarshManvar's answer</a> proposes.)</p>
