1.

Explain the command terraform fmt in the context of Terraform.

Answer»

Terraform configuration files are rewritten using the terraform fmt command in a consistent structure and style. This command uses a subset of the Terraform language style conventions, as well as some small readability tweaks. Other Terraform commands that produce Terraform configuration will produce files that follow the terraform fmt style, therefore following this style in your own files will assure consistency. Because formatting selections are always subjective, you may disagree with terraform fmt's choices. This command is PURPOSELY opinionated and lacks customization options because its PRIMARY goal is to promote stylistic consistency throughout Terraform codebases, even THOUGH the chosen style will never be everyone's favourite.

Syntax:

terraform fmt [options] DIR

By default, fmt LOOKS for configuration files in the current directory. If the dir option is provided, it will instead scan the specified directory.

The following are the flags that are available:

  • -list=false - This option doesn't show files with discrepancies in formatting.
  • -write=false - This option prevents the input files from being overwritten. (When the input is STDIN or -check, this is implied.)
  • -diff - Shows the differences in formatting modifications.
  • -check - Verifies that the input is properly FORMATTED. If all input is properly formatted, the exit status will be 0, else it will be non-zero.
  • -recursive - Process files from subdirectories as well.


Discussion

No Comment Found