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
consul validate /etc/consul.d/
# validate a single file
consul validate consul.hcl
# validate several paths
consul validate consul.hcl consul.d/Options
| Argument / flag | What it does |
|---|---|
| <file|dir> | Config file or directory to validate (repeatable) |
| -config-format hcl|json | Force the format when the extension is ambiguous |
| -quiet | Suppress 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.
Using this in CI
A runner has no kubeconfig, no cached context, and no interactive auth. Every kubectl invocation in CI needs the context supplied explicitly, and most confusing CI failures here are the command running against the wrong cluster or no cluster at all.
# never rely on the ambient context on a runner
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get pods
# confirm what you are actually connected to before mutating anything
kubectl config current-context
kubectl cluster-info
# fail fast instead of hanging on an unreachable API server
kubectl --request-timeout=30s get nodes