Fetch a value from KV store, but its not a Key:Value pair in the template

481 Views Asked by At

All, Is it possible to convert my server.cert.template file in to server.cert using consul template and consul KV.

In my Consul am defining a KV pair as follows:

    SERVER_SSL_CERT = 4r4ffqh;fhq2fhwhhqwpihpvhqv'in3v3rvnrqpnrvnnvvqn

And my server.cert.template looks as follows:

    -----BEGIN CERTIFICATE-----
    ${SERVER_SSL_CERT}
    -----END CERTIFICATE-----

Earlier I was using local files for this substitution. Can consul handle this and if so how ? How do I query consul to dump this value here ?

Thanks

1

There are 1 best solutions below

0
On

So I got this working as follows. Sharing it in case some one comes across a similar situation. Contents of my template file are as follows:

    {{$host := "hostname" -}}
    {{$keyname := printf "Project/%s/Certs/SERVER_SSL_CERT" $host -}}
    {{ key $keyname }}

When we run consul-template on it, it will print the value as part of the last line.