<p>I am not able to iterate over range using helm templating for networkpolicies to allow egress with ports to ipBlock. Below I have my values.yaml:</p>
<pre><code>networkPolicy:
  ports:
    - port: xxxx
      cidrs:
        - ipBlock:
            cidr: x.x.x.x/32
        - ipBlock:
            cidr: x.x.x.x/32
    - port: xxxx
      cidrs:
        - ipBlock:
            cidr: x.x.x.x/32
        - ipBlock:
            cidr: x.x.x.x/32
</code></pre>
<p>And my template file is</p>
<pre><code>spec:
  podSelector:
    matchLabels:
      policy: allow
  policyTypes:
  - Egress
  egress:
{{- range $item := .Values.networkPolicy.ports}}  
  - ports:
    - port: {{$item.port}}
      protocol: TCP
    to:
{{$item.cidrs | nindent 4 }}
{{- end }}
</code></pre>
<p>I get when I try to template.</p>
<pre><code>spec:
  podSelector:
    matchLabels:
      policy: allow
  policyTypes:
  - Egress
  egress:
</code></pre>
<p>What is expected</p>
<pre><code>spec:
  podSelector:
    matchLabels:
      policy: allow
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: xxxx
      protocol: TCP
    to:
    - ipBlock:
        cidr: x.x.x.x/32
    - ipBlock:
        cidr: x.x.x.x/32
  - ports:
    - port: xxxx
      protocol: TCP
    to:
    - ipBlock:
        cidr: x.x.x.x/32
    - ipBlock:
        cidr: x.x.x.x/32

</code></pre>
<p>Thanks in advance!</p>

Divin D
<p>I have changed it to below and it worked.</p>
<p>values.yaml</p>
<pre><code>networkPolicy:
  ports:
    - port: xxxx
      ipBlock:
        - cidr: x.x.x.x/32
        - cidr: x.x.x.x/32
    - port: xxx
      ipBlock:
        - cidr: x.x.x.x/32
        - cidr: x.x.x.x/32
</code></pre>
<p>And my template file is</p>
<pre><code>spec:
  podSelector:
    matchLabels:
      nwp: allow-backends
  policyTypes:
  - Egress
  egress:
  {{- range $item := .Values.networkPolicy.ports}}
  - ports:
    - port: {{ $item.port }}
      protocol: TCP
    to:
    {{- range $item.ipBlock }}
    - ipBlock:
        cidr: {{ .cidr }}
    {{- end }}
  {{- end }}
</code></pre>
