Question 1 · choose 1
A team wants its pull request checks to fail when any .tf file is not in canonical format, without the check rewriting files in the build workspace. Which command should the pipeline run?
- Aterraform fmt -diff
- Bterraform validate -json
- Cterraform fmt -list=false
- Dterraform fmt -check
Show the answer and why
Aterraform fmt -diff
Incorrect
-diff shows the formatting changes but still rewrites the files and exits successfully.
Bterraform validate -json
Incorrect
validate checks syntax and consistency, not formatting.
Cterraform fmt -list=false
Incorrect
That only stops fmt from listing the files it changes.
Dterraform fmt -check
Correct
-check exits with a non-zero status when input is not formatted and implies -write=false, so files are not modified.
fmt -check is the CI form of fmt: report and fail, never write.
HashiCorp documentation