Sitelet https://web.archive.org/web/20211018205241/https://github.com/apache/apisix/discussions/5222
Skip to content

Is it possible to read environment variables from yaml configuration files? #5222

Unanswered
abbluiz asked this question in Q&A
Is it possible to read environment variables from yaml configuration files? #5222
Oct 13, 2021 · 2 answers · 8 replies

I want to use different configuration depending on my environment on some YAML configuration files, specially in conf/apisix.yaml in stand-alone mode. Is it possible to read from environment variable like ${VAR} inside YAML file?

Replies

2 suggested answers
·
8 replies
@abbluiz

I saw this, however it is not flexible enough for me. I would like do store OAuth 2.0 endpoints and client secret in environment variables and use them inside the files like ${OAUTH_INTROSPECTION_ENDPOINT}. This is because I commit my route config whilst using stand alone mode.

@tzssangglass

try use ${{VAR}} in config.yaml, refer to

# To configure via environment variables, you can use `${{VAR}}` syntax. For instance:

@abbluiz

Yes, but what about other configuration files, like apisix.yaml when using stand alone mode? It seems that this syntax does not work for it.

sounds like a good feature.

5 replies
@abbluiz

Yes, it would be great to be natively supported. To anyone interested, for now I am creating a temporary docker container that parses the yaml file and replaces with my environment variables using a Python script.

@tokers

I think so, it's my understanding that secrets are not suitable to be written in the configuration directly, env should be supported.

@spacewander

The variable resolve is done in

local ok, err = resolve_conf_var(user_conf)

We can do the same thing with

local function read_apisix_yaml(premature, pre_mtime)
after refactor.

PR is welcome!

@tzssangglass

tzssangglass Oct 15, 2021
Collaborator

I've turned this discussion into an issue. refer to:#5243 see:#5244

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
4 participants