I understand that you can set and override defaults with default.toml
and user.toml
which works great for well known values.
What about cases where the “default” value can/should be “autodiscovered” or generally relies on “dynamic” data. (My initial thought was to call it “Automatic” data because that’s sort of what it would be in Chef.)
What I really want to do is:
# default.toml
[server]
bind_address = "{{sys.ip}}"
# user.toml
[server]
bind_address = "0.0.0.0"
Say I have a service that has an API and a Cluster address. In most cases I want the “api” and “cluster” addresses to be the same, and those both to be the IP on the first device (which I’m assuming is what sys.ip
is… but that’s probably worth a separate thread). But sometimes I’ll run my cluster behind a load balancer, then in that case I’d want to broadcast the IP of the load balancer instead of each of my individual IPs as my “API Address” and have my nodes communicate with each other on their “cluster address” in the private segment behind the LB.
Another use case is when running in a container, I very well may not know my IP, so populating my config file with {{sys.ip}}
may be mostly sufficient until I want to put my containers behind a LB. I really don’t want to compile a new package just to update one config setting… then would I have two packages with just that difference?
Or what about an application connecting to a database. Eventually I want to get my database cluster habitized, but for now I’m using an external database cluster. So maybe to help me transition I do:
# default.toml
[database]
address = {{bind.database.leader.sys.ip}}
# user.toml
[database]
address = 192.168.100.152
Then when I’m ready I just remove my user.toml
I can also see a use-case for populating {{sys.org}}
and {{sys.group}}
in my default.toml
. “When running in production we just use “production” everywhere, but when testing we configure our apps differently with specific naming.”