Can I use a Config.Provider without using a mix release?

I wish to run a config provider before runtime.exs kicks in so I can alter the config dynamically on start up. Is this possible to do with a config provider?

The docs say to use a config provider you have to do this in the mix.exs

releases: [
  demo: [
    config_providers: [...]
  ]
]

which implies I have to use a release.

You could theoretically not define a provider and instead invoke whatever code you need from runtime.exs. That should also work for Mix and releases.

2 Likes

Yea that’s true! I can also set config in the application.ex too I suppose.

When I did Application.get_all_env(:my_app) in runtime.exs it didn’t seem like the config in runtime was set yet, unlike in application.ex:

import Config
config(:my_app, thing: 1)
# This is []
IO.inspect(Application.get_all_env(:my_app))

The use case is having templates for secrets in the config:

config(:my_app, 
  magic_number: {"GOOGLE_SECRET", :integer, "MY_SECRET_NUMBER"}
)

The config provider would parse that, get the secret from wherever (eg google) and replace the tuple with the actual secret value.

I guess defining my own fn like this would work:

secret_config(:my_app, 
  magic_number: {"GOOGLE_SECRET", :integer, "MY_SECRET_NUMBER"}
)