Skip to content
Latchkey

consul validate: Check Consul Config in CI

consul validate parses one or more Consul configuration files or directories and reports errors without starting an agent.

Running consul validate in a PR catches a malformed agent config before it is shipped and refuses to start in production.

What it does

consul validate loads the given Consul config files (HCL or JSON) exactly as the agent would, checks syntax and semantic constraints, and prints "Configuration is valid!" on success or the specific error on failure. It exits non-zero on any error, which is what makes it a clean CI gate.

Common usage

Terminal
consul validate /etc/consul.d/
# validate a single file
consul validate consul.hcl
# validate several paths
consul validate consul.hcl consul.d/

Options

Argument / flagWhat it does
<file|dir>Config file or directory to validate (repeatable)
-config-format hcl|jsonForce the format when the extension is ambiguous
-quietSuppress the success message, print only errors

In CI

Add consul validate ./consul.d/ to the lint stage so a broken agent config fails the pipeline instead of the node. It needs no running cluster or server, so it is a fast, self-contained gate.

Common errors in CI

"Error parsing ...: invalid character" or "At ...: expected ..." points at an HCL/JSON syntax error at that line. "\"data_dir\" is required" and similar tell you a required field is missing. "Config validation failed" with a semantic message (for example an invalid retry_join) means the syntax is fine but a value is not allowed.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →