Terraform-Associate-004 practice question 11 of 35

Running terraform fmt without any flags in a directory with Terraform configuration files will check the formatting of those files, but will never change their contents.

Full set: 360 questions
Answer options
A: True
B: False
Correct Answer:
FALSE
Explanation

The statement is incorrect. The primary function of the terraform fmt command, when run without any flags, is to scan the current directory and rewrite Terraform configuration files to a canonical format and style. This action directly modifies the contents of any files that do not conform to the standard formatting. The behavior of only checking for formatting issues without changing the files is achieved by using the -check flag.

Why Incorrect

The statement claims that terraform fmt will "never change their contents" by default. This is the opposite of its actual default behavior, which is to reformat and thus change the files in place.

References

1. HashiCorp Developer Documentation, Terraform CLI, fmt Command:

Location: https://developer.hashicorp.com/terraform/cli/commands/fmt

Quote/Paraphrase: The documentation's opening sentence states, "The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style." This explicitly confirms that the command's purpose is to change file content.

Quote/Paraphrase for -check flag: The documentation describes the -check option as follows: "Check if the input is already formatted. Exit with a non-zero status code if the input is not formatted." This distinguishes the "checking" behavior as a non-default option.

Scroll to Top