{"action":"created","issue":{"url":"https://api.github.com/repos/kelseyhightower/confd/issues/332","repository_url":"https://api.github.com/repos/kelseyhightower/confd","labels_url":"https://api.github.com/repos/kelseyhightower/confd/issues/332/labels{/name}","comments_url":"https://api.github.com/repos/kelseyhightower/confd/issues/332/comments","events_url":"https://api.github.com/repos/kelseyhightower/confd/issues/332/events","html_url":"https://github.com/kelseyhightower/confd/pull/332","id":104977124,"number":332,"title":"add ability to define dynamic template resource files","user":{"login":"crunchywelch","id":3017686,"avatar_url":"https://avatars.githubusercontent.com/u/3017686?v=3","gravatar_id":"","url":"https://api.github.com/users/crunchywelch","html_url":"https://github.com/crunchywelch","followers_url":"https://api.github.com/users/crunchywelch/followers","following_url":"https://api.github.com/users/crunchywelch/following{/other_user}","gists_url":"https://api.github.com/users/crunchywelch/gists{/gist_id}","starred_url":"https://api.github.com/users/crunchywelch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crunchywelch/subscriptions","organizations_url":"https://api.github.com/users/crunchywelch/orgs","repos_url":"https://api.github.com/users/crunchywelch/repos","events_url":"https://api.github.com/users/crunchywelch/events{/privacy}","received_events_url":"https://api.github.com/users/crunchywelch/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-04T21:57:54Z","updated_at":"2016-02-20T00:29:41Z","closed_at":"2016-02-20T00:29:41Z","pull_request":{"url":"https://api.github.com/repos/kelseyhightower/confd/pulls/332","html_url":"https://github.com/kelseyhightower/confd/pull/332","diff_url":"https://github.com/kelseyhightower/confd/pull/332.diff","patch_url":"https://github.com/kelseyhightower/confd/pull/332.patch"},"body":"Here is a small piece of code that allows you to define template resource files based on arbitrary keys in etcd (or presumably whatever backend). Here is the general idea:\r\n\r\n```\r\ncore@lb1 ~ $ ls /etc/confd/conf.d/\r\nhaproxy.tomld\r\ncore@lb1 ~ $ etcdctl ls /_confd\r\n/_confd/0491f260-d089-4263-a7f7-74c0144b6874\r\n/_confd/0491f260-d089-4263-a7f7-XXXXXXXXXXXXXX\r\ncore@lb1 ~ $ etcdctl get /_confd/0491f260-d089-4263-a7f7-74c0144b6874\r\nhaproxy.tomld\r\ncore@lb1 ~ $\r\n```\r\n\r\nWe grab any values in /_confd, and source the specified resource template file (I appended mine with \"d\" to avoid complaints from the standard file parsing routine)\r\n\r\nThe only other thing that happens is the \"dest\" value does a simple token replacement based on the key entered in /_confd to allow you to specify the location / name of the destination config file. \r\n\r\nHAProxy example:\r\n\r\n```\r\n[template]\r\nprefix = \"/haproxy\"\r\nsrc = \"haproxy.tmpl\"\r\ndest = \"/home/core/{{.token}}.cnf\"\r\nowner = \"core\"\r\nmode = \"0644\"\r\nkeys = [\r\n  \"/backend/primary\",\r\n  \"/upstream\",\r\n]\r\ncheck_cmd = \"/usr/sbin/nginx -t -c {{.src}}\"\r\nreload_cmd = \"/usr/sbin/service nginx reload\"\r\n```\r\n\r\nI'm happy to change the defaults (_confd, or $token value) if this is something you'd like to merge, just let me know if it is worth taking time to clean up and run tests, etc!\r\n\r\nthx"},"comment":{"url":"https://api.github.com/repos/kelseyhightower/confd/issues/comments/186466120","html_url":"https://github.com/kelseyhightower/confd/pull/332#issuecomment-186466120","issue_url":"https://api.github.com/repos/kelseyhightower/confd/issues/332","id":186466120,"user":{"login":"kelseyhightower","id":1123322,"avatar_url":"https://avatars.githubusercontent.com/u/1123322?v=3","gravatar_id":"","url":"https://api.github.com/users/kelseyhightower","html_url":"https://github.com/kelseyhightower","followers_url":"https://api.github.com/users/kelseyhightower/followers","following_url":"https://api.github.com/users/kelseyhightower/following{/other_user}","gists_url":"https://api.github.com/users/kelseyhightower/gists{/gist_id}","starred_url":"https://api.github.com/users/kelseyhightower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kelseyhightower/subscriptions","organizations_url":"https://api.github.com/users/kelseyhightower/orgs","repos_url":"https://api.github.com/users/kelseyhightower/repos","events_url":"https://api.github.com/users/kelseyhightower/events{/privacy}","received_events_url":"https://api.github.com/users/kelseyhightower/received_events","type":"User","site_admin":false},"created_at":"2016-02-20T00:29:41Z","updated_at":"2016-02-20T00:29:41Z","body":"I like this idea, but I want to revisit how we do this. I want to draw up a proposal then figure out all the backends where confd can pull templates from."}}