I want to use files to import key value pairs into a folder in Consul.
e.g.
I have a config folder in consul k/v tab.
I have a file (json/txt) with key/value pairs separated by colon
[{key : value}, {key, value}…]
I import file into config folder
consul kv import(or put) config/ @file.json expected outcome
config folder now has all the key/ value pairs from the file separated into their own key/ value pairs.
I understand that I might not be explaining perfectly, so feel free to ask any questions. If there is already a way to do it with consul alone, please let me know. I know there are 3rd party libraries (git2consul etc) that can do that, but I want to know if there is a best way to do that (preferably not using a 3rd party library, but if that is the only way then that is fine).
$ cat in.json | jq -r '.[] | to_entries[] | "config/"+.key+ " "+ .value' | xargs consul kv put
Success! Data written to: config/k1
Success! Data written to: config/k2
Success! Data written to: config/k3
$ consul kv get config/k1
v1
...
I remember seeing that somewhere. I was hoping that we can do it without a third party library, but I had a feeling that won’t be possible. Thank you for your help!