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

17 comments
Sign in to comment
BurakkoOption: B
Sep 2, 2022

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

BereOption: B
Jan 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.

InformationOverloadOption: B
Dec 29, 2022

Tested in lab, B is correct.

BennaniHaythemOption: A
Apr 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.

NunyabiznesOption: B
Apr 1, 2023

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

Stanislav4907Option: A
Apr 8, 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
Jul 18, 2023

default write value is false donc A is correct

LemonadeSoftwareOption: A
Nov 16, 2023

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
Dec 3, 2023

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

sameedOption: B
Nov 29, 2022

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

princajenOption: A
Feb 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
Mar 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

tychoOption: B
Apr 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
Jul 20, 2023

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

arun00028Option: A
Oct 13, 2023

Option A

Ramdi1Option: A
Nov 23, 2023

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
Dec 6, 2023

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

ARBAROption: A
Apr 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.