Linux command
tofu-fmt 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Format current directory
tofu fmt
Format recursively
tofu fmt -recursive
Check formatting (exit non-zero if not formatted)
tofu fmt -check
Show diff of formatting changes
tofu fmt -diff
Format from stdin and write to stdout
cat main.tf | tofu fmt -
说明
tofu fmt rewrites OpenTofu configuration files to a canonical format and style. It applies a subset of the HCL language style conventions, along with other minor adjustments for readability. OpenTofu is the open-source fork of Terraform maintained by the Linux Foundation. By default, tofu fmt scans the current directory for configuration files. If you provide a target directory, it will scan that directory. If a single file is provided, only that file is processed. A hyphen (_-_) as target reads from standard input.
参数
- -list=_false_
- Don't list the files containing formatting inconsistencies.
- -write=_false_
- Don't overwrite the input files (implied by -check or when reading from stdin).
- -diff
- Display diffs of formatting changes.
- -check
- Check if the input is formatted. Exit status is 0 if all input is properly formatted; non-zero otherwise.
- -recursive
- Also process files in subdirectories. By default, only the given directory is processed.
FAQ
What is the tofu-fmt command used for?
tofu fmt rewrites OpenTofu configuration files to a canonical format and style. It applies a subset of the HCL language style conventions, along with other minor adjustments for readability. OpenTofu is the open-source fork of Terraform maintained by the Linux Foundation. By default, tofu fmt scans the current directory for configuration files. If you provide a target directory, it will scan that directory. If a single file is provided, only that file is processed. A hyphen (_-_) as target reads from standard input.
How do I run a basic tofu-fmt example?
Run `tofu fmt` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -list=_false_ do in tofu-fmt?
Don't list the files containing formatting inconsistencies.