The consul_kv datasource allows Jerakia to retreive values from Hashicorp Consul using the key value store features (Consul KV)
Global configuration for consul is placed in jerakia.yaml
under the consul
configuration key. The following configuration options are supported. Jerakia uses the Diplomat library to integrate with Consul KV
url
: HTTP URL to connect to the Consul KV API, default: http://localhost:8500acl_token
: Optional ACL token to supply with the API requestsoptions
: A hash of options to provide to Faraday, see the Diplomat documentation for informationconsul:
url: http://localhost:8888
The following options are available when declaring the consul_kv datasource within a Jerakia lookup
datacenter
: A string, Optionally specify a dc (datacenter) for the lookupto_hash
: Boolean, default: true. Will consolidate the results into a hash instead of an array.recursive
: Boolean, default: false. Will return the entire data structure from Consul KV rather than just the requested keysearchpath
: Array, default: [ ‘/’ ]. A set of prefixes, Jerakia will iterate through each level of the searchpath appending the namespace and lookup key# consul kv put environment/development/apache/port 8080
Success! Data written to: environment/development/apache/port
# consul kv put common/apache/port 80
Success! Data written to: common/apache/port
policy :default do
lookup :main do
datasource :consul_kv, {
:searchpath => [
"environment/#{scope[:environment]}",
"common"
]
}
end
end
Data can now be looked up hierarchically.
# bin/jerakia lookup port -n apache
80
# bin/jerakia lookup port -n apache --metadata environment:development
8080
The key that gets passed to Consul KV consists of the search prefix