range can't iterate over list [x y]

2.5k Views Asked by At

I have this template in my helm chart:

{{ $appEnvs := list "dev" "uat" }}

{{- range $env := $appEnvs }}
...
{{- end }}

I am getting this error :

<$appEnvs>: range can't iterate over [dev uat]

I spent longtime trying many things like : {{- range $env := toYaml $appEnvs }} and {{- range $env := tuple $appEnvs }} and others.. but no way.

However, when i put the list directly without variable , it works.. I mean {{- range $env := list "dev" "uat" }} works !?!?

How to iterate over a VARIABLE created by the sprig function list ?

1

There are 1 best solutions below

0
On
apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
  test: |-
    {{- $appEnvs := list "dev" "uat" }}
    {{- range $idx, $env := $appEnvs }}
    {{ $env }}: {{ $env }}
    {{- end }}

output

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
  test: |-
    dev: dev
    uat: uat
  1. range
...
    {{- $appEnvs := list "dev" "uat" }}
    {{- range $appEnvs }}
    {{ . }}: {{ . }}
    {{- end }}
...

output

...
    dev: dev
    uat: uat
...