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 馃槱
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}}
Most helpful comment
projects.yamlneeds to contain a yaml hash as the root element. Also you need to usefromYamlasreadFilereads it as text where what you want seems like a map object.projects.yaml
helmfile.yaml