Helmfile: (OS) Environment variable can't be used in environments file (YAML)

Created on 13 Mar 2020  路  4Comments  路  Source: roboll/helmfile

When I use the environment config as below
environments: dev: values: - environments/values-common.yaml - environments/values-dev.yaml - branch: {{ requiredEnv "GIT_CURRENT_BRANCH" }}

I can use the variable branch, but when I put this line in the file values-common.yaml, I can't use it and the variable is not set (map has no entry for key "branch")

I would be handy to use the line below in an environment file (such as values-common.yaml or values-dev.yaml in my example)

branch: {{ requiredEnv "GIT_CURRENT_BRANCH" }}

Most helpful comment

Hi! I believe this is the same issue as #1142.

Well, I think this is different. I have got the following situation.

helmfile.yaml

environments:
  default:
    values:
      - values.yaml
---
releases:
  - name: nginx
    chart: bitnami/nginx
    values:
      - hosts:
        - name: {{ .Values.host }}
          path: /

values.yaml

host: {{ requiredEnv "HOST" }}

I expect this will work, because the becauses the situation below works:
helmfile.yaml

environments:
  default:
    values:
      - host: {{ requiredEnv "HOST" }}
---
releases:
  - name: nginx
    chart: bitnami/nginx
    values:
      - hosts:
        - name: {{ .Values.host }}
          path: /

All 4 comments

Hi! I believe this is the same issue as #1142.

Hi! I believe this is the same issue as #1142.

Well, I think this is different. I have got the following situation.

helmfile.yaml

environments:
  default:
    values:
      - values.yaml
---
releases:
  - name: nginx
    chart: bitnami/nginx
    values:
      - hosts:
        - name: {{ .Values.host }}
          path: /

values.yaml

host: {{ requiredEnv "HOST" }}

I expect this will work, because the becauses the situation below works:
helmfile.yaml

environments:
  default:
    values:
      - host: {{ requiredEnv "HOST" }}
---
releases:
  - name: nginx
    chart: bitnami/nginx
    values:
      - hosts:
        - name: {{ .Values.host }}
          path: /

Anything new on this one? It seems to me kind of a different situation, as well, no?

Here's another scenario:

Case 1

releases:                                                                          
- name: foo                                                                     
  chart: stable/foo                                                             
  values:                                                                          
  - x.bar: {{ env "BAR" }}           
  - x.baz: {{ env "BAZ" }}                                   

If BAR and BAZ are set, the above will render as expected - x.bar and x.baz will not be empty.

Case 2

releases:                                                                          
- name: foo                                                                     
  chart: stable/foo                                                             
  values:                                                                          
  - config.yaml.gotmpl                                 

where config.yaml.gotmpl is:

x:
  bar: {{ env "BAR" }}           
  baz: {{ env "BAZ" }}                                   

In this case both x.bar and x.baz will be empty. Is this the expected behavior?

What prevents OS environment variables from being available/rendered in both cases?

What's different compared to the docs?

Thanks in advance!

It turns out that x.bar was empty, because the contents of config.yaml.gotmpl were:

x:
  bar: {{ env "BAR " }}           

Notice the whitespace.

Not sure how this should be handled, since env variable names do not include whitespaces by convention.

Was this page helpful?
0 / 5 - 0 ratings