Skip to content

conn3x fmt

conn3x fmt rewrites configuration files in the standard layout: consistent indentation, aligned = signs, and spacing. It changes layout only, never meaning.

Terminal window
conn3x fmt [options] [PATH...]

With no PATH, it formats the current directory. A directory formats the files in it, a file formats that file, and - reads from standard input and writes the result to standard output.

fmt formats .circuit.hcl files along with .tf, .tofu, .tfvars, .tftest.hcl and .tofutest.hcl files. A directory scan picks them up, and you can name one directly:

Terminal window
conn3x fmt web.circuit.hcl

So conn3x fmt -check -recursive in CI covers your circuits as well.

Option Description
-check Change nothing, and exit 3 if any file needs formatting. Lists the files that do.
-diff Print the changes as a diff.
-write=false Don’t write to the files. Use it with -diff to preview.
-list=false Don’t print the names of the files that changed.
-recursive Format subdirectories too.
-no-color Don’t use terminal colors.

See OpenTofu’s fmt page for more.

Format everything under the current directory:

Terminal window
conn3x fmt -recursive

Fail CI when a file isn’t formatted:

Terminal window
conn3x fmt -check -recursive

Preview the changes:

Terminal window
$ conn3x fmt -diff -write=false
main.tf
--- old/main.tf
+++ new/main.tf
@@ -1,3 +1,3 @@
variable "region" {
-type=string
+ type = string
}
Code Meaning
0 Success. With -check, every file is formatted.
2 An error, such as a syntax error or a file type fmt doesn’t handle.
3 Only with -check: some files need formatting.