How to use variables with .Values in helm template

10/3/2017

I have the following values.yaml:

vrIds:
  - 51
  - 52
51.vip: 169.254.1.1
52.vip: 169.254.1.2

I have the following template:

{{ range $index, $element := .Values.vrIds }}
  vrrp.{{$element}}.vip: <<How do I get the value of $element.vip>>
{{ end }}

How do I get the value of $element.vip for each vrid?

-- Pradeep
go-templates
kubernetes-helm

1 Answer

11/1/2017

You need to modify your values.yaml a little:

vrIds:
  51: 169.254.1.1
  52: 169.254.1.2

And use the following construction inside your template files:

{{- range $key, $value := .Values.vrIds }}
  vrrp.{{ $key }}.vip: {{ $value }}
{{- end }}
-- nickgryg
Source: StackOverflow