How to use Variables in consul-template config file?
I have consul templates which I want to run and below is my consul-template configuration:
vault {
address = "http://$VAULT_ADDR:8200"
token = "sometoken"
unwrap_token = false
renew_token = false
}
template {
source = "somepath/agent.crt.tpl"
destination = "somepath/agent.key"
command = "sh -c 'date && systemctl restart consul'"
}
I've tried the whole day to put the vault address in dynamic way or pass it as variable or take it from env variable or by consul-template API without success.
In the end I ended up writing this sorcery in my service file:
ExecStart=/bin/sh -c "/usr/local/sbin/consul-template -config /opt/consul/templates/tls-consul.hcl \
-vault-addr http://$(curl -s -XGET $(hostname -I | awk '{ print $1 }'):8500/v1/health/service/vault | jq .[0].Node.Address -r):8200"
is there any convenient way to do this? Can I use environment variable for token
part somehow or am I forced to hardcode it?