feat: support environment variables in config-default.yaml
Description
Comment in config.yaml shows that APISIX support use environment variables in yaml
# To configure via environment variables, you can use `${{VAR}}` syntax. For instance:
#
# deployment:
# role: traditional
# role_traditional:
# config_provider: etcd
# etcd:
# host:
# - http://${{ETCD_HOST}}:2379
But in config-defautl.yaml, it does not work.
-- apisix/cli/file.lua
local default_conf = yaml.load(default_conf_yaml)
if not default_conf then
return nil, "invalid config-default.yaml file"
end
local_conf_path = profile:customized_yaml_path()
if not local_conf_path then
local_conf_path = profile:yaml_path("config")
end
local user_conf_yaml, err = util.read_file(local_conf_path)
if not user_conf_yaml then
return nil, err
end
local is_empty_file = true
for line in str_gmatch(user_conf_yaml .. '\n', '(.-)\r?\n') do
if not is_empty_yaml_line(line) then
is_empty_file = false
break
end
end
if not is_empty_file then
local user_conf = yaml.load(user_conf_yaml)
if not user_conf then
return nil, "invalid config.yaml file"
end
local ok, err = resolve_conf_var(user_conf)
if not ok then
return nil, err
end
ok, err = merge_conf(default_conf, user_conf)
if not ok then
return nil, err
end
end
The ${{ VAR }} syntax is processed by resolve_conf_var, but it is only called for user_conf.
To support it in config-default.yaml, run resolve_conf_var for default_conf as well.
ping @bzp2010
@flea1lt The issue is not completed. It hasn't been merged due to the implementation change of default-config.yaml and its implementation should change accordingly.
Please reopen.
Thank you @flea1lt.
Once #11343 is merged, I'll rework this PR
config-default.yaml is not meant to be modified by users. This is part of the reason why it was moved to a hardcoded lua file. Wondering why it needs to support env var? Can this issue be closed?
@kayx23 Since the default configuration has been converted to a hardcoded Lua file, this feature is no logger necessary.