github.com/kanishk98/terraform@v1.3.0-dev.0.20220917174235-661ca8088a6a/website/docs/cli/commands/fmt.mdx (about) 1 --- 2 page_title: 'Command: fmt' 3 description: >- 4 The terraform fmt command rewrites configuration files to a canonical format 5 and style. 6 --- 7 8 # Command: fmt 9 10 The `terraform fmt` command is used to rewrite Terraform configuration files 11 to a canonical format and style. This command applies a subset of 12 the [Terraform language style conventions](/language/syntax/style), 13 along with other minor adjustments for readability. 14 15 Other Terraform commands that generate Terraform configuration will produce 16 configuration files that conform to the style imposed by `terraform fmt`, so 17 using this style in your own files will ensure consistency. 18 19 The canonical format may change in minor ways between Terraform versions, so 20 after upgrading Terraform we recommend to proactively run `terraform fmt` 21 on your modules along with any other changes you are making to adopt the new 22 version. 23 24 We don't consider new formatting rules in `terraform fmt` to be a breaking 25 change in new versions of Terraform, but we do aim to minimize changes for 26 configurations that are already following the style examples shown in the 27 Terraform documentation. When adding new formatting rules, they will usually 28 aim to apply more of the rules already shown in the configuration examples 29 in the documentation, and so we recommend following the documented style even 30 for decisions that `terraform fmt` doesn't yet apply automatically. 31 32 Formatting decisions are always subjective and so you might disagree with the 33 decisions that `terraform fmt` makes. This command is intentionally opinionated 34 and has no customization options because its primary goal is to encourage 35 consistency of style between different Terraform codebases, even though the 36 chosen style can never be everyone's favorite. 37 38 We recommend that you follow the style conventions applied by `terraform fmt` 39 when writing Terraform modules, but if you find the results particularly 40 objectionable then you may choose not to use this command, and possibly choose 41 to use a third-party formatting tool instead. If you choose to use a 42 third-party tool then you should also run it on files that are generated 43 automatically by Terraform, to get consistency between your hand-written files 44 and the generated files. 45 46 ## Usage 47 48 Usage: `terraform fmt [options] [target...]` 49 50 By default, `fmt` scans the current directory for configuration files. If you 51 provide a directory for the `target` argument, then `fmt` will scan that 52 directory instead. If you provide a file, then `fmt` will process just that 53 file. If you provide a single dash (`-`), then `fmt` will read from standard 54 input (STDIN). 55 56 The command-line flags are all optional. The following flags are available: 57 58 * `-list=false` - Don't list the files containing formatting inconsistencies. 59 * `-write=false` - Don't overwrite the input files. (This is implied by `-check` or when the input is STDIN.) 60 * `-diff` - Display diffs of formatting changes 61 * `-check` - Check if the input is formatted. Exit status will be 0 if all input is properly formatted. If not, exit status will be non-zero and the command will output a list of filenames whose files are not properly formatted. 62 * `-recursive` - Also process files in subdirectories. By default, only the given directory (or current directory) is processed.