-
Notifications
You must be signed in to change notification settings - Fork 191
Description
We use an environment variable to define where to look up the file for the dotenv provider.
We want to set this to default to a specific location in the users home directory (e.g. ~/default.env
) but Teller does not expand ~
or $HOME
.
Example (does not work):
providers:
dotenv:
kind: dotenv
maps:
- id: default
path: >-
{{ get_env(
name="TELLER_ENV_FILE",default="~/default.env")
}}
The following error is given via the CLI, even when ~/default.env
exists:
$ teller show
Error: failed to open file `~/default.env`
Caused by:
No such file or directory (os error 2)
Location:
/private/tmp/teller-20240519-8895-wwtpqa/teller-2.0.7/teller-cli/src/cli.rs:296:23
It would be great if Teller could parse the default value in order to resolve at least the home directory of the user.
Workarounds
Require the user to define the environment variable
This is not ideal since it requires extra setup by default.
Use Tera template engine
I've found that I can rewrite the .teller.yml
file with Terra. My new teller config ends up looking like this:
# {% set home_dir = get_env(name="HOME") -%}
# {% set default_teller_file = home_dir ~ 'default.env' %}
providers:
dotenv:
kind: dotenv
maps:
- id: default
path: >-
{{ get_env(
name="TELLER_ENV_FILE",default=default_teller_file)
}}
This does indeed work, since it requires no interpolation.
Note: I added #
's before each of the set
lines because it isn't valid yaml and my IDE kept complaining.
Conclusion
If Teller is interested in supporting variable expansion, that would solve this issue nicely.
If not, then the Terra template workaround can work to solve this problem, but there is no clear path to guide a Teller user on how to do this (as a non-rust user, it took me some effort to even figure out that Terra parses the config file.) The documentation could be updated with such a strategy.
If you are interested in a PR being contributed to document the technique, I'd be happy to provide one.