I have my values.yaml as below
account:
- name: abc
value: value1
- name: xyz
value: value2
i want to refer them in my helm template. instead of referring them as
accounts:
- name: acount1
value: "{{ .Values.account.abc }}"
- name: account2
value: "{{ .Values.account.xyz }}"
is there a way i can refer entire block in my template as
accounts:
{{ .Values.account }}
and it will iterate through all the values passed in the values.yaml file ?
Could able to figure it out. This worked.
accounts:
{{- range $account := .Values.account }}
- name: {{ $account.name }}
value: {{ $account.value | quote }}
{{- end }}
Helm has a minimally-documented toYaml
function that will write an arbitrary structure as YAML. You will also need it indented to be under accounts:
in the output structure, and the sprig indent
or nindent
functions can help with this.
accounts: {{- .Values.account | toYaml | trim | nindent 2 }}