Can i refer entire section from values file in the helm template?

10/17/2019

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 ?

-- krishna
kubernetes-helm

2 Answers

10/17/2019

Could able to figure it out. This worked.

accounts:
   {{- range $account := .Values.account }}
   - name: {{ $account.name }}
     value: {{ $account.value | quote }}
   {{- end }}
-- krishna
Source: StackOverflow

10/17/2019

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 }}
-- David Maze
Source: StackOverflow