I am trying to do an append operation in helper_tpl file
{{/*
Get Region List and append to a variable
*/}}
{{- define "plugin.regionList" -}}
{{- $regionString := "" -}}
{{- $regionValueFile := (.Files.Get .Values.secondaryValueFile) | fromYaml }}
{{- range $key, $val := $regionValueFile.regional }}
append .{{ $key }}
{{- $regionString := printf "%s.%s" $regionString $key -}}
{{ end }}
{{- printf "%s" $regionString -}}
{{- end -}}
Now the output I get is
append .au-syd
append .br-sao
append .ca-tor
append .eu-de
append .eu-fr2
append .eu-gb
append .jp-osa
append .jp-tok
append .us-east
append .us-south
While what I expect is au-syd.br-sao.ca-tor...
something like this.
Is there a way to achieve this
I do not understand append .{{ $key }}
. You should also remove :
before =
from this line as it reinitialize the variable in each iteration:
{{- $regionString = printf "%s.%s" $regionString $key -}}
So the final code would be something like:
{{- define "plugin.regionList" -}}
{{- $regionString := "" -}}
{{- $regionValueFile := (.Files.Get .Values.secondaryValueFile) | fromYaml }}
{{- range $key, $val := $regionValueFile.regional }}
{{- $regionString = printf "%s.%s" $regionString $key -}}
{{ end }}
{{- printf "%s" $regionString -}}
{{- end -}}