Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 172


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

Show Answer
Correct Answer: B

Running terraform fmt without any flags will automatically rewrite Terraform configuration files to adhere to a canonical format and style. This means it will modify the files to ensure they are correctly formatted according to Terraform's standards. It does not simply check the formatting; it actively changes the files if they are not formatted correctly.

Discussion

21 comments
Sign in to comment
BurakkoOption: B
Mar 2, 2023

The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style.

Jd1233Option: A
Mar 19, 2023

This should be A - The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style. https://www.terraform.io/cli/commands/fmt

DevoteamAnalytix
Nov 26, 2023

So it IS CHANGING, so "without changing" is false, so the answer is "FALSE" => B

BereOption: B
Jul 24, 2024

Running terraform fmt without any flags in a directory with Terraform configuration files will not only check the formatting of those files but will also rewrite them to a canonical format if they are not already formatted correctly. If you want to check the formatting without making any changes, you should use the -check flag with the command. This flag will instruct Terraform to check if the input is formatted correctly and return a non-zero exit code if it isn't, without modifying the files.

keiffo2
Mar 6, 2023

"terraform fmt -check" will not write the proposed formatting changes to the config file

Bobby1977
Apr 5, 2023

It should be A

InformationOverloadOption: B
Jun 29, 2023

Tested in lab, B is correct.

NunyabiznesOption: B
Oct 2, 2023

If you want to check the formatting without modifying the files, you can use the -check flag: terraform fmt -check

BennaniHaythem
Oct 16, 2023

True. Running terraform fmt without any flags will check the formatting of the Terraform configuration files in the current directory, and it will update the files to conform to the standard formatting rules defined by Terraform. However, it will not change the contents of the files. If you want to modify the contents of the files to match the formatting rules, you can run terraform fmt -write=true.

Stanislav4907Option: A
Oct 9, 2023

Yes, that's correct. Running terraform fmt without any flags in a directory with Terraform configuration files will check the formatting of those files without changing their contents. terraform fmt is a command that formats your Terraform configuration files according to a set of standard conventions. This makes your code more readable, easier to maintain, and more consistent with best practices.

SimoAzOption: A
Jan 18, 2024

default write value is false donc A is correct

LemonadeSoftware
May 16, 2024

A 100% Running terraform fmt without any flags in a directory with Terraform configuration files checks the formatting without altering the content because the command is used to format and standardize the layout of Terraform configuration files according to the defined conventions. When executed without any flags, it checks whether the files comply with the expected formatting standards but does not modify the content unless there's a need for formatting changes to align with the defined conventions. If you want to format it, you have to add the “-w” flag

diegoaOption: A
Jun 3, 2024

If no flag is given, fmt rewrites the Terraform configuration files to a canonical format and style.https://developer.hashicorp.com/terraform/cli/commands/fmt

Bobby1977
Apr 9, 2023

Usage: terraform fmt [options] [target...] By default, fmt scans the current directory for configuration files. If you provide a directory for the target argument, then fmt will scan that directory instead. If you provide a file, then fmt will process just that file. If you provide a single dash (-), then fmt will read from standard input (STDIN). It is A

sameedOption: B
May 30, 2023

It will not only check the content but reformat it if required.

princajenOption: A
Aug 16, 2023

A. True. Running terraform fmt without any flags in a directory with Terraform configuration files will check the formatting of those files without changing their contents. The command will print a list of files that need formatting changes, but it will not actually make any changes to the files. This can be useful for checking if files have been manually edited or if they need to be updated to conform to a new format. If you want to apply the formatting changes to the files, you can use the -write flag or the -check flag to check and write the formatting changes at the same time.

David_C_90
Sep 16, 2023

This is wrong. $ terraform fmt -h Rewrites all Terraform configuration files to a canonical format. (...) --- If you want to check without changing the files, use -write=false or -check

tycho
Oct 18, 2023

apparently according to this question the changing of the format is a change in the file content, therefore answer is B ; somehow it wants to highlight the diff between -check option and without it

VSMuOption: B
Jan 20, 2024

Tested. The answer is B. Running terraform fmt updates (formats) the .tf files in the current working directory.

arun00028
Apr 13, 2024

Option A

Ramdi1Option: A
May 23, 2024

just read the document, it says if you use it without a flag or directory it will not process anything. however if you add a flag it will process it

AlbionOption: B
Jun 6, 2024

Tested. The terraform fmt command, format files content. No need for any flag

ARBAROption: A
Oct 21, 2024

Running terraform fmt without any flags in a directory with Terraform configuration files will indeed check the formatting of those files without changing their contents. It will only modify the formatting to comply with Terraform's style conventions if necessary, without altering the actual content of the files.