consulconsul-templateconsul-kv

consul-template failed writing file: missing destination


I'm facing an issue on consul with consul-template. I'm trying to get a data from my kv store and send it to a .pem file with my template.hcl

The problem is that, i have fill my template.hcl and when i'm trying to start my consul-template with this command :

consul-template -template /etc/consul.d/templates.hcl -once

It is awsnering me with this message :

2022-07-20T09:42:35.426Z [ERR] (cli) error rendering "/etc/consul.d/templates.hcl" => "": failed writing file: missing destination

Here is my template.hcl file :

consul {
        address = "consul.service.consul:8500"
        retry {
                enabled = true
                attempts = 12
                backoff = "250ms"
        }
}

template {
        contents = "{{ key "certs/pos.in.kv.store/cert.pem" }}"
        destination = "/etc/ssl/haproxy/star.cert.emplacment.fr.pem"
        perms = 0640
        exec {
                command = "sudo haproxy -v -c -f /etc/haproxy/haproxy.cfg && sudo haproxy -D -p /var/run/haproxy.pid
-f"
        }
}

The destination is already set so i don't know where there is a problem, can you help me ?

I don't know where to look at anymore :(


Solution

  • It seems you are mixing the template configuration file with the template itself. All your template language syntax should go inside a different file, like 'star.cert.emplacment.fr.pem.ctmpl' which will be rendered by consul-template into your destination.

    Create a source file star.cert.emplacment.fr.pem.ctmpl, which has all the double curlies {{ }} like

    {{ key "certs/pos.in.kv.store/cert.pem" }}
    

    then, inside your configuration file (hcl) indicate that file as the source:

    template {
        source = "/etc/ssl/haproxy/star.cert.emplacment.fr.pem.ctml"
        destination = "/etc/ssl/haproxy/star.cert.emplacment.fr.pem"