I may be trying to use this incorrectly however I have a JSON data structure as the value of one of my keys in Consul.
{
"zookeeperPort": 3181,
"kafkaPort": 9092,
"brokers": {
"kafka1.consul.net": {
"brokerId": 111,
"anotherVal": "test"
},
"kafka2.consul.net": {
"brokerId": 112,
"anotherVal": "test"
}
}
}
I’m able to parse using parseJSON just fine but it feels a bit clunky. Is there a better way to extract brokerId
especially if I already know which key I am looking for? If I can’t do that, is there a way to assign the output of this range to a variable I can use in multiple places within my template?
{{- $properties := key (print $consulPath "/server.properties") | parseJSON -}}
broker.id={{ range $b, $bv := $properties.brokers }}{{- if eq $b "kafka1.consul.net" }}{{ range $k, $v := $bv }}{{- if eq $k "brokerId" }}{{- $v }}{{ end }}{{ end }}{{ end }}{{ end }}
I hope that makes sense. Thanks!