To check if all code in a Terraform configuration with multiple modules is properly formatted without making changes, what command should be run?

Prepare for the HashiCorp Terraform Associate Exam. Utilize flashcards and multiple-choice questions with detailed hints and explanations. Boost your confidence and be ready for success!

Multiple Choice

To check if all code in a Terraform configuration with multiple modules is properly formatted without making changes, what command should be run?

Explanation:
To verify formatting across a multi-module Terraform project without changing files, you want to run the fmt command in check mode across every directory. The -check flag makes Terraform report if any file would be reformatted and it does not write changes. The -recursive flag ensures this check travels into all subdirectories, including each module, so nothing is missed. Together, terraform fmt -check -recursive will scan the entire configuration, indicate any formatting issues, and leave all files untouched. Omitting -recursive could leave modules unchecked, and using a write-enabled mode would modify files, which isn’t desired here.

To verify formatting across a multi-module Terraform project without changing files, you want to run the fmt command in check mode across every directory. The -check flag makes Terraform report if any file would be reformatted and it does not write changes. The -recursive flag ensures this check travels into all subdirectories, including each module, so nothing is missed. Together, terraform fmt -check -recursive will scan the entire configuration, indicate any formatting issues, and leave all files untouched. Omitting -recursive could leave modules unchecked, and using a write-enabled mode would modify files, which isn’t desired here.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy