Skip to main content
Consul Template is a HashiCorp tool designed to render configuration files dynamically using data from a Consul cluster. Running as a standalone daemon alongside a Consul agent, it continuously watches key/value entries and regenerates files when values change. This ensures seamless configuration updates without manual restarts.

Workflow

  1. Define a template file with placeholders (e.g., app.ctmpl).
  2. Start the Consul agent on your server:
  3. Launch the consul-template process, specifying the template and target:
  4. The daemon retrieves key/value pairs from Consul.
  5. Placeholders in the template are replaced with live data.
  6. The rendered file is saved to disk.
  7. An optional command (like a service reload) is executed to apply updates.
By default, Consul Template polls Consul every two seconds. Adjust the interval with the -wait flag or in HCL.
The image is a flowchart explaining the process of using a consul-template, starting from a VM launch, executing the consul-template, creating a config file, and launching an application, with interactions with a Consul Cluster.

Key Benefits

Example HCL Configuration

Create /etc/consul-template/config.hcl:
Run the daemon:
Ensure the Consul agent is running and reachable. When ACLs are enabled, include the token parameter in your HCL or CLI invocation.

Watch Video