title: Caculating the global index for two ranges in Kubernetes Sprig/helm templates?
body: <p>In a Helm Chart I have to following values</p>
  
  <pre><code>dataCenters:
    - name: a
      replicas: 3
    - name: b
      replicas: 2
  </code></pre>
  
  <p>When generating the template I would like my output to be like the following </p>
  
  <pre><code>server.1 = a-1
  server.2 = a-2
  server.3 = a-3
  server.4 = b-1
  server.5 = b-2
  </code></pre>
  
  <p>I tried this code</p>
  
  <pre><code>{{- $index := 0 -}}
  {{ range $dc := .Values.cluster.dataCenters -}}
  {{ range $seq := (int $dc.replicas | until) -}}
  {{- $index := (add $index 1) -}}
  server.{{ $index }}={{ $dc.name }}-{{ $seq }}
  {{ end -}}
  {{ end -}}
  </code></pre>
  
  <p>however in helm templates I don't thing you can reassign the value of the index as my 4th line is attempting and because of that I get out</p>
  
  <pre><code>server.1 = a-1
  ...
  server.1 = b-2
  </code></pre>
  
  <p>How does one calculates the global index <strong>0 to 4</strong> (1 to 5 in my situation) using the Sprig/Helm templating language?</p>