[Unit]
Description=Run Consul-template to watch wireguard network updates

[Service]
{%- if consul.tokens.wireguard is defined %}
Environment="CONSUL_HTTP_TOKEN={{ consul.tokens.wireguard }}"
{%- endif %}

Environment="CONSUL_HTTP_ADDR=https://127.0.0.1:€# lookup('env','CONSUL_HTTPS_PORT') | default(8501, true) | int #€"
Environment="CONSUL_CACERT=€# layerops_tls_ca_file #€"

TimeoutStartSec=0
ExecStart=€# local_bin_path #€/consul-template \
  -default-left-delimiter '{€' \
  -default-right-delimiter '€}' \
  -template="/etc/wireguard/€# lookup('env','WIREGUARD_INTERFACE') | default('wg0', true) #€.conf.tmpl:/etc/wireguard/€# lookup('env','WIREGUARD_INTERFACE') | default('wg0', true) #€.conf:€# local_bin_path #€/wg_reload"
ExecStop=/bin/kill -9 $MAINPID

Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
