helmfile icon indicating copy to clipboard operation
helmfile copied to clipboard

Reference other variables in values.yaml.gotmpl

Open mseiwald opened this issue 3 years ago • 5 comments

Hi,

I would like to achieve something like the below.

values.yaml.gotmpl

customer: xxxxx
domain: {{ .Values.customer }}.example.com

This obviously does not work. Is there another way to reference a previous variable in values.yaml.gotmpl that I'm missing?

Thanks!

mseiwald avatar Feb 03 '22 15:02 mseiwald

Try to use the recommendation from this document: https://github.com/roboll/helmfile/blob/master/docs/writing-helmfile.md#layering-state-template-files - something like this:

customer: xxxxx
---
domain: {{ .Values.customer }}.example.com

MurzNN avatar Feb 04 '22 09:02 MurzNN

Hi @mumoshu, Hi @MurzNN

I would like to add my question here, I hope that's fine.

Is this also possible with environment values? Can I use Go templating and the state layering there? What I'm trying to do is something like:

org:
  keyvault:
    kv1: org-kv1.vault.azure.net
---
org:
  database:
    postgres96:
      host: ref+azurekeyvault://{{ .Values.org.keyvault.kv1 }}/azure-postgresql-96-host
      user: ref+azurekeyvault://{{ .Values.org.keyvault.kv1 }}/azure-postgresql-96-user
      ...
    postgres11:
      host: ref+azurekeyvault://{{ .Values.org.keyvault.kv1 }}/azure-postgresql-11-host
      user: ref+azurekeyvault://{{ .Values.org.keyvault.kv1 }}/azure-postgresql-11-user
      ...

But it does not work. I get something like:

err: failed to read helmfile.yaml: failed to load environment values file "environments/dev.yaml.gotmpl": failed to render [environments/dev.yaml.gotmpl], because of template: stringTemplate:17:42: executing "stringTemplate" at <.Values.org.keyvault.kv1>: map has no entry for key "org"

Any help would be very appreciated. Thank you!

pathob avatar Feb 09 '22 11:02 pathob

Hi, Currently I have the same problem like @pathob

helmfile.yaml

releases:
- name: myservice
  namespace: test
  chart: chart/parent
  values:
  - values.yaml.gotmpl

values.yaml.gotmpl

customer: xxxxx
---
domain: {{ .Values.customer }}.example.com

this leads to the following errors @MurzNN

helmfile write-values
> ... in ./helmfile.yaml: failed to render values files "values.yaml.gotmpl": failed to render [values.yaml.gotmpl], because of template: stringTemplate:3:18: 
executing "stringTemplate" at <.Values.customer>: map has no entry for key "customer"

Thanks for your support.

Ro-Fo avatar May 04 '22 15:05 Ro-Fo

@pathob @Ro-Fo Hey! As far as I remember, I don't think --- was supported in values file templates. It's supported in helmfile.yaml templates so all I can say is that you'd better handle such "layering" in helmfile yamls, not values templates.

You could also try combining dict, merge, readFile, and fromYaml to merge objects, and finally outputting yaml by piping the result to toYaml in your values template.

mumoshu avatar May 06 '22 01:05 mumoshu