title: Kubernetes Helm chart: Use _helpers.tpl to concat values and feed back into Values.yaml
body: <p>I am new to Kubernetes, Helm, and Golang. Basically, I'm trying to concat strings in my values.yaml file to populate another value in my values.yaml file. I'm using _helpers.tpl to do this (in an attempt to understand Helm and Golang better).  I could just write "users: "datafeed:password:::incoming" " in my values.yaml file and be done with it; but would like to avoid that. </p>
  
  <p>I have the following in my values.yaml file:</p>
  
  <pre><code>sftp:
    users: ""
    username: "datafeed"
    password: "password"
    incoming: "incoming"
  </code></pre>
  
  <p>And want the <strong>final</strong> values.yaml file to read:</p>
  
  <pre><code>sftp:
    users: "datafeed:password:::incoming"
    username: "datafeed"
    password: "password"
    incoming: "incoming"
  </code></pre>
  
  <p>To do this, I am trying to edit the _helpers.tpl file. I have tried</p>
  
  <pre><code>{{- define "sftp.users" -}}
  {{- .Values.sftp.users: .Values.sftp.username+":"+.Values.sftp.password+":::"+.Values.sftp.incoming -}}
  {{- end -}}
  </code></pre>
  
  <p>and</p>
  
  <pre><code>{{- define "sftp.users" -}}
  {{- .Values.sftp.users:= .Values.sftp.username+":"+.Values.sftp.password+":::"+.Values.sftp.incoming -}}
  {{- end -}}
  </code></pre>
  
  <p>Then I tried making each segment a variable (and deleted the explicit values in the values.yaml file):</p>
  
  <pre><code>{{- define "sftp.users" -}}
  {{ $username:= "datafeed" }}
  {{ $password:= "password" }}
  {{ $incoming:= "incoming" }}
  {{- .Values.sftp.users= {{$username}}+":"+{{$password}}":::"+{{$incoming}} -}}
  </code></pre>
  
  <p>and then setting the fields/keys explicitly:</p>
  
  <pre><code>username: {{ .Values.sftp.username | default "datafeed" }}
  password: {{ .Values.sftp.password | default "password" }}
  incoming: {{ .Values.sftp.incoming | default "incoming" }}
  {{- .Values.sftp.users:= username+":"+password+":::"+incoming -}}
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>{{define "username"}}datafeed{{end}}
  {{define "password"}}password{{end}}
  {{define "incoming"}}incoming{{end}}
  {{define "users"}}{{template "username"}}:{{template "password"}}:::{{template "incoming"}}{{end}}
  {{- printf "users" -}}
  {{- .Values.sftp.users: users -}}
  </code></pre>
  
  <p>I have also looked at previous posts:
  <a href="https://stackoverflow.com/questions/46719082/helm-helpers-tpl-calling-defined-templates-in-other-template-definitions?rq=1">Helm _helpers.tpl: Calling defined templates in other template definitions</a>
  <a href="https://stackoverflow.com/questions/45278655/kubernetes-helm-combine-two-variables-with-a-string-in-the-middle?newreg=1f09fb8852fa44f2871d96bec723d61c">Kubernetes Helm, combine two variables with a string in the middle</a>
  <a href="https://stackoverflow.com/questions/56679428/how-to-get-values-from-values-yaml-to-helpers-tpl-in-helm-charts">How to get values from values.yaml to _helpers.tpl in helm charts</a></p>
  
  <p>None of this seems to work. I can't tell if it's my approach or my syntax. Probably both.</p>