Use consul as a config source for HAProxy
esell ba399c4f37 add sample restart script 3 years ago
src/ don't crap out if we get a bad response from consul 3 years ago
.gitignore moving away from red/black, making more generic 3 years ago
LICENSE.txt first commit 3 years ago More readme updates 3 years ago
conf.json support different default config locations in consul 3 years ago add sample restart script 3 years ago


Builds out the HAproxy config file based on data in consul. Whenever a service change is detected a new config is created and HAproxy is reloaded.


Conf-builder currently uses gb to build although no outside libraries are needed:

go get
git clone  
cd conf-builder  
gb test
gb build


Place the conf.json file in the same directory as the executable and run it, that’s about it. The configurable values are:


  • The command used to reload/restart haproxy


  • An array of strings that will be the VIPs you want in your HAproxy config. These should match the names used in the frontend/backend section of consul (see below)


  • The location of your consul server and the port if needed


  • The root of your config in the consul key/value store. Everythign else hangs off of this (see below)


  • The name/locatin of the HAproxy config file that will be output


  • The name/location of the temp file used during the config building process

Consul layout

The expected consul layout would look like:

├── backend
│   └── myApp
│       ├── balance = balancer type (roundrobin, etc)
│       ├── catalogMapping = consul service name
│       ├── mode = proxy type (tcp, http, etc)
│       ├── staticConf = any static config you'd like to add
│       └── type = dynamic/static member updates
├── defaults = defaults section of the HAProxy config
├── frontend
│   └── myApp
│       ├── bindOptions = any additional bind options to add (SSL, etc)
│       ├── listenPort port for HAProxy to listen on
│       ├── mode = proxy type (tcp, http, etc)
│       └── staticConf = any static config you'd like to add
└── global = global section of the HAproxy config

Where myApp is the name you want to use for your VIP. You do not have to have a frontend AND a backend, you can just use one or the other if you’d like and of course you can have multiples (myApp, anotherApp, yetAnother, etc) as long as they follow the layout.