Comparing consul key/values between properties

One liner to compare a set of key/values from two different consul locations

Comparing consul key/values between properties

Consul is a great key/value store, when a property, eg a set of key/values, is populated manually to then feed services down the chain is prone to errors. The following one-liner will compare a source with a destination for all the keys and values.
The only requirements to run this is to have curl and jq installed.
Given a consul server (consul.server.com) and the path to an app (myapp) with a good property (source) that you want to compare against (destination) run:

s=source ; d=destination ; for k in `curl -s https://consul.server.com/v1/kv/myapp/${s}/\?keys | jq -r '.[]'`; do rk=`basename $k` ; vsf=`curl -s https://consul.server.com/v1/kv/myapp/${s}/$rk\?raw` ; vs=`curl -s https://consul.server.com/v1/kv/myapp/${d}/$rk\?raw`; if [ "$vs" = "$vsf" ]; then echo "OK $rk is the same value" ; else echo "DIFF$rk differs. $d:${vs} $s:${vsf}" ; fi ; done

The above will output something like the following:

OK KEY0 is the same value
OK KEY1 is the same value
OK KEY2 is the same value
DIFF KEY3 differs. source:-Xmx10G -Xms10G destination:-Xmx20G -Xms20G

Enjoy!

vernon plumbing