Helmfile: Cannot convert the output of readFile into List for iteration

Created on 15 Jun 2020  路  1Comment  路  Source: roboll/helmfile

I have a yaml file projects.yaml

# projects.yaml
- yako
- pera
- okta

In values.yaml.gotmpl, i want to iterate thru the content of projects.yaml :

# values.yaml.gotmpl
{{ $projects := readFile 'projects.yaml' }}
{{ range $_, $project := $projects }}
   # do something with $project . e.g: tpl (readFile 'proj-config.yaml') (dict $name $project)
{{ end}}

Unfortunately , i got this error :

failed to render [values.yaml.gotmpl], because of template: stringTemplate:60:41: executinng "stringTemplate" at <$projects>: range can't iterate over projects:
- yako
- pera
- okta

I made a lot of blind attempts to make it work :

  • {{ range $_, $project := $projects | fromYaml }}
  • {{ range $_, $project := $projects | toYaml }}
  • {{ range $_, $project := $projects | list }}

No way 馃槱

Most helpful comment

projects.yaml needs to contain a yaml hash as the root element. Also you need to use fromYaml as readFile reads it as text where what you want seems like a map object.

projects.yaml

# projects.yaml
projects:
- yako
- pera
- okta

helmfile.yaml

{{ $projects := readFile "projects.yaml" | fromYaml }}
values:
- projects:
{{ range $_, $project := get "projects" $projects }}
  - {{ $project }}
{{ end}}

>All comments

projects.yaml needs to contain a yaml hash as the root element. Also you need to use fromYaml as readFile reads it as text where what you want seems like a map object.

projects.yaml

# projects.yaml
projects:
- yako
- pera
- okta

helmfile.yaml

{{ $projects := readFile "projects.yaml" | fromYaml }}
values:
- projects:
{{ range $_, $project := get "projects" $projects }}
  - {{ $project }}
{{ end}}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

maver1ck picture maver1ck  路  3Comments

klebediev picture klebediev  路  3Comments

aslafy-z picture aslafy-z  路  4Comments

mojochao picture mojochao  路  4Comments

cilerler picture cilerler  路  4Comments