{"action":"created","issue":{"url":"https://api.github.com/repos/CiscoCloud/haproxy-consul/issues/18","labels_url":"https://api.github.com/repos/CiscoCloud/haproxy-consul/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/CiscoCloud/haproxy-consul/issues/18/comments","events_url":"https://api.github.com/repos/CiscoCloud/haproxy-consul/issues/18/events","html_url":"https://github.com/CiscoCloud/haproxy-consul/issues/18","id":115386052,"number":18,"title":"Why HAPROXY_DOMAIN ?","user":{"login":"auguster","id":1567457,"avatar_url":"https://avatars.githubusercontent.com/u/1567457?v=3","gravatar_id":"","url":"https://api.github.com/users/auguster","html_url":"https://github.com/auguster","followers_url":"https://api.github.com/users/auguster/followers","following_url":"https://api.github.com/users/auguster/following{/other_user}","gists_url":"https://api.github.com/users/auguster/gists{/gist_id}","starred_url":"https://api.github.com/users/auguster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/auguster/subscriptions","organizations_url":"https://api.github.com/users/auguster/orgs","repos_url":"https://api.github.com/users/auguster/repos","events_url":"https://api.github.com/users/auguster/events{/privacy}","received_events_url":"https://api.github.com/users/auguster/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-11-05T22:05:52Z","updated_at":"2015-11-06T11:00:39Z","closed_at":null,"body":"I've been using haproxy-consul for some weeks now and I still don't get the requirement of specifying the HAPROXY_DOMAIN environment variable for consul use.\r\n\r\nWouldn't it be easier to just define the acl in the tmpl file like this:\r\n```\r\nacl host_{{ .Name }} hdr(host) -m beg {{ .Name }}.\r\nuse_backend {{ .Name }}_backend if host_{{ .Name }}\r\n```\r\nNotice the dot following the second occurrence of `{{ .Name }}`. It is here to ensure that services don't get confused (for example \"mail\" and \"mailinglist\").\r\n\r\nI'm not sure though how this would work on the marathon counterpart but I don't believe HAPROXY_DOMAIN should be a requirement for at least consul.\r\n\r\nI went even further and extended the tmpl file for multiple domains use, using consul's tags for storing the domains under the form `<domain>_<tld>`.\r\n\r\nHere are the relevant parts:\r\n```\r\n# Generated automatically by consul-template\r\n\r\n#tagged services, tag is use for domain information\r\n{{ range $tag, $services := services | byTag }}\r\n{{ range $services}}\r\n    acl host_{{ .Name }}_{{ $tag}} hdr(host) -i {{ .Name }}.{{ $tag |replaceAll \"_\" \".\" }} \r\n    use_backend {{ .Name }}_{{$tag}}_backend if host_{{ .Name }}_{{ $tag }}\r\n{{ end }}\r\n{{ end }}\r\n\r\n#not tagged services, the url starting part is used\r\n{{range services}}{{if eq (.Tags |len) 0 }}\r\n    acl host_{{ .Name }} hdr(host) -m beg {{ .Name }}.\r\n    use_backend {{ .Name }}_backend if host_{{ .Name }}\r\n{{ end }}{{ end }}\r\n\r\n#backend definition for tagged services\r\n{{ range $tag, $services := services | byTag }}{{range $services}}\r\nbackend {{ .Name }}_{{$tag}}_backend{{ range service (print $tag \".\" .Name) }}\r\n   server {{ .Node }} {{ .Address }}:{{ .Port }}{{ end }}\r\n{{ end }}{{ end }}\r\n\r\n#backend definition for untagged services\r\n{{ range services }}{{ if eq (.Tags |len) 0 }}\r\nbackend {{ .Name }}_backend{{ range service .Name }}\r\n   server {{ .Node }} {{ .Address }}:{{ .Port }}{{ end }}\r\n{{ end }}{{ end }}\r\n```\r\nThere is a lot of room for improvement ;-)"},"comment":{"url":"https://api.github.com/repos/CiscoCloud/haproxy-consul/issues/comments/154381166","html_url":"https://github.com/CiscoCloud/haproxy-consul/issues/18#issuecomment-154381166","issue_url":"https://api.github.com/repos/CiscoCloud/haproxy-consul/issues/18","id":154381166,"user":{"login":"auguster","id":1567457,"avatar_url":"https://avatars.githubusercontent.com/u/1567457?v=3","gravatar_id":"","url":"https://api.github.com/users/auguster","html_url":"https://github.com/auguster","followers_url":"https://api.github.com/users/auguster/followers","following_url":"https://api.github.com/users/auguster/following{/other_user}","gists_url":"https://api.github.com/users/auguster/gists{/gist_id}","starred_url":"https://api.github.com/users/auguster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/auguster/subscriptions","organizations_url":"https://api.github.com/users/auguster/orgs","repos_url":"https://api.github.com/users/auguster/repos","events_url":"https://api.github.com/users/auguster/events{/privacy}","received_events_url":"https://api.github.com/users/auguster/received_events","type":"User","site_admin":false},"created_at":"2015-11-06T11:00:39Z","updated_at":"2015-11-06T11:00:39Z","body":"That's also what I did :)"}}