Pradeep
Pradeep

Reputation: 1398

How to use variables with .Values in helm template

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?

Upvotes: 5

Views: 25095

Answers (1)

nickgryg
nickgryg

Reputation: 28743

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 }}

Upvotes: 12

Related Questions