0

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

ambikanair
  • 4,004
  • 11
  • 43
  • 83

1 Answers1

1

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 -}}
Andromeda
  • 1,205
  • 1
  • 14
  • 21