<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>try something like</p>
<pre><code>{{range $i, $e := $}}
{{if $i}},{{end}}
{{$e}}{{end}}
</code></pre>
<p>If actually look for the index and if it's zero it's wont to add the <code>,</code> at last. here is if is not behave like normal it checks the <strong>index</strong> also.</p>
<pre><code>{{- range $i, $e := . -}}
            {{if $i}}, {{end}}prefix_{{$e}}
        {{- end}}
</code></pre>
<p>above loop will give output like : <code>prefix_one, prefix_two, prefix_three</code></p>
<p><a href="https://play.golang.org/p/KuRh55BHna8" rel="nofollow noreferrer">https://play.golang.org/p/KuRh55BHna8</a></p>
<p>Read more at : <a href="https://groups.google.com/g/golang-nuts/c/XBScetK-guk/m/Bh7ZFz6R3wQJ" rel="nofollow noreferrer">https://groups.google.com/g/golang-nuts/c/XBScetK-guk/m/Bh7ZFz6R3wQJ</a></p>
