Consul
Configure Consul Template
You can configure Consul Template with a configuration file written in the HashiCorp Configuration Language. The configuration is also JSON compatible. For a full list of configuration options, refer to the Consul Template configuration reference.
To start using Consul Template, run the Consul Template CLI with the -config
flag pointing at the configuration file:
$ consul-template -config "/my/config.hcl"
Specify this argument multiple times to load multiple configuration files. The right-most configuration takes the highest precedence. If you provide the path to a directory instead of a file, all of the files in the given directory are merged in lexical order, recursively. Be aware that symbolic links are not followed.
The full list of available commands and options is available in the Consul Template CLI reference.
Note Commands specified on the CLI take precedence over a config file.
Not all available fields for the configuration file are required. For example, if you are not retrieving secrets from Vault, you do not need to specify a Vault configuration section. Similarly, if you are not logging to syslog, you do not need to specify a syslog configuration.
For additional security, tokens may also be read from the environment using the CONSUL_TOKEN
or VAULT_TOKEN
environment variables. We recommend that you do not include plain-text tokens in a configuration file.
Example
The following example configures Consul Template for a Consul agent and renders a template with a value from the Consul KV store. It writes the output to a file on disk.
consul {
address = "127.0.0.1:8500"
auth {
enabled = true
username = "test"
password = "test"
}
}
log_level = "warn"
template {
contents = "{{key \"hello\"}}"
destination = "out.txt"
exec {
command = "cat out.txt"
}
}