<p>I'm having trouble rendering a template for a Helm Chart that needs to have easily expandable amounts of nodes and replicas. I get the below error message. What's odd is I do not get the below error message if I remove the inner loop to not nest loops. I'm completely new to go, but this seems valid. I'm at a loss.</p>

<p>Error:</p>

<pre><code>$ helm install . --dry-run --debug
Error: render error in "app-on-k8s/templates/configmap_configd.yaml": template: app-on-k8s/templates/configmap_configd.yaml:18:77: executing "app-on-k8s/templates/configmap_configd.yaml" at &lt;.Values.nodeCount&gt;: can't evaluate field Values in type int
</code></pre>

<p>This is the relevant section from my values.yaml file:</p>

<pre><code># number of nodes / shards
nodeCount: 5
replicaCount: 3
</code></pre>

<p>And the relevant section from my template file:</p>

<pre><code>    &lt;default&gt;
        {{range $i, $e := until (atoi (printf "%d" (int64 .Values.nodeCount))) }}
                &lt;node&gt;
                {{range $j, $k := until (atoi (printf "%d" (int64 .Values.replicaCount))) }}   #line 18
                    &lt;replica&gt;
                        &lt;host&gt;{{ $.Release.Name }}-{{$j}}&lt;/host&gt;
                        &lt;port&gt;{{ $.Values.service.rpc_port }}&lt;/port&gt;
                    &lt;/replica&gt;
                {{end}}    
                &lt;/node&gt;
        {{end}}
    &lt;/default&gt;
</code></pre>

user797963
<p>The problem is, when you are using <code>.Values.replicaCount</code> in the second loop,<code>.</code> scope has been changed and now pointing at <code>.Values.nodeCount</code>. So <code>.Values.replicaCount</code> now pointing to <code>.Values.nodeCount.Values.replicaCount</code>. Since, there is no such field in values.yaml file you are getting this error.</p>

<p>Use <code>$.Values.replicaCount</code> instead of <code>.Values.replicaCount</code> in second loop.</p>

<p>Ref: <a href="https://docs.helm.sh/chart_template_guide/#looping-with-the-range-action" rel="noreferrer">helm.sh</a></p>
