Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for dynamic keys, using environment variables #344

Closed
wants to merge 1 commit into from

Conversation

davidquarles
Copy link

This is quick hack, based on the behavior described in #73 and #310.
Example / our use case:

[template]
src = "database.php.tmpl"
dest = "/var/www/site/application/config/database.php"
keys = [
    "/cluster/${CLUSTER_ID}/mysql/master/internal",
    "/cluster/${CLUSTER_ID}/mysql/slave/internal",
]

Template:

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

{{ $clusterID := getenv "CLUSTER_ID" }}

$db['default']['hostname'] = "{{ getv (printf "/cluster/%s/mysql/master/internal" $clusterID) }}"
// ...

$db['slave'] = $db['default'];
$db['slave']['hostname'] = "{{ getv (printf "/cluster/%s/mysql/slave/internal" $clusterID) }}"
?>

@davidquarles
Copy link
Author

I can totally amend the docs, if this is something you're interested in merging. We could also explicitly specify which environment vars we're looking for in the config and limit expansion to those, but I figured this was a step in the right direction. Let me know what you think. Thanks!

@kelseyhightower
Copy link
Owner

While this seems to work for some use cases it increases the complexity of confd. The original goal of confd was to be simple to understand and reason about after deployment. This change will introduce dynamic keys into the mix and goes against the spirt of confd a bit, where I want to keep things as explicit as possible.

I don't see a limit to this feature, and I will soon see requests to pull vars from all the backends so they can be used to bind the dynamic keys. Please understand my desire to keep confd super simple and serve as a simple bridge between applications and configuration stores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants