<p>I have the following content in values.yaml and virtualservice.yaml:
I want to create template file using above value but getting error while helm rendenring template.</p>
<p><code>values.yaml</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>istio:
  enabled: true
  virtualService:
    enabled: true
    virtualServices:
      &quot;0&quot;: 
        name: hello-app
        gateways: 
           - gateway-new
        hosts:
          - prod.abc.com
        apps:
          name: primary
          path: &quot;/api&quot;
          routes:
            &quot;0&quot;:
              weight: 100
              port: 8080
              name: hello-app
            &quot;1&quot;:
              weight: 0
              port: 8080
              name: hello-app-canary 
        &quot;1&quot;: 
            name: hello-app-internal
            gateways: 
              - mesh
            hosts:
              - hello-app.test.prod.svc.cluster.local
            apps:
              name: internal
              path: &quot;/api&quot;
              routes:
                &quot;0&quot;:
                  weight: 100
                  port: 9081
                  name: hello-app
                &quot;1&quot;:
                  weight: 0
                  port: 9081
                  name: hello-app-canary  
</code></pre>
<p><code>virtualservice.yaml</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>{{- if ((.Values.istio).enabled) }}
{{- if ((.Values.istio.virtualService).enabled) }}
{{- range $key, $value := .Values.istio.virtualService.virtualServices }}
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: {{ .name }}
  namespace: {{ $.Release.Namespace }}
  labels:
{{ include &quot;common.labels&quot; $ | indent 4 }}
spec:
  gateways:
  {{- range .gateways }}
  - {{.}}
  {{- end }}
  hosts:
  {{- range .hosts }}
  - {{.}}
  {{- end }}
  http:
  {{- range $app := $value.apps }}
  - match:
      - uri:
          prefix: &quot;/{{ $app.path }}&quot;
    name: {{ $app.name }}
    route:
    {{- range $route := $app.routes }}
    - destination:
          host: {{ $route.name }}
          port:
            number: {{ $route.port  }}
      weight: {{ $route.weight  }}
    {{- end }}
    {{- end }}
{{- end }}
{{- end }}
{{- end }}
</code></pre>
<p>How do I iterate if I have more than one list using range? With the above template, I am getting the error:</p>
<pre><code> at &lt;$app.path&gt;: can't evaluate field path in type interface {}
</code></pre>
<p>Any help is highly appreciated.</p>

Anup Dubey
<p>First of all, it looks like the virtual service &quot;1&quot; has one extra indent (right now it is under virtual service &quot;0&quot; section, but it should be under &quot;virtualServices&quot;).</p>
<p>Moreover, If you want to iterate over the apps of each virtual service, the <code>apps</code> field should be a list, but right now it is a dictionary. Therefore, when you iterate with <code>range $app := $value.apps</code> you are actually iterating over the fields of <code>apps</code>, which leads to the error you are getting.</p>
<p>Here's the fixed version of <code>values.yam</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>istio:
  enabled: true
  virtualService:
    enabled: true
    virtualServices:
      &quot;0&quot;: 
        name: hello-app
        gateways: 
           - gateway-new
        hosts:
          - prod.abc.com
        apps:
        - name: primary
          path: &quot;/api&quot;
          routes:
            &quot;0&quot;:
              weight: 100
              port: 8080
              name: hello-app
            &quot;1&quot;:
              weight: 0
              port: 8080
              name: hello-app-canary 
      &quot;1&quot;: 
          name: hello-app-internal
          gateways: 
            - mesh
          hosts:
            - hello-app.test.prod.svc.cluster.local
          apps:
          - name: internal
            path: &quot;/api&quot;
            routes:
              &quot;0&quot;:
                weight: 100
                port: 9081
                name: hello-app
              &quot;1&quot;:
                weight: 0
                port: 9081
                name: hello-app-canary  

</code></pre>
