Which statement about Terraform code indentation is correct?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

Which statement about Terraform code indentation is correct?

Explanation:
Indentation in Terraform (HCL) is about readability and consistency. The language doesn’t require a specific amount of whitespace for parsing, but the recommended style is two spaces per indentation level. This standard keeps nested blocks and attributes easy to scan and compare across configurations. It also aligns with the formatter Terraform provides (terraform fmt), which outputs code using two-space indentation, reinforcing a uniform look across projects. Using two spaces per level helps distinguish hierarchy clearly, for example when you have a resource block with nested blocks and multiple attributes. Four spaces, three spaces, or a tab can lead to inconsistent appearance between editors or teams, making reviews slower and increasing the chance of misreadings. So, two spaces is the best-fit choice because it matches common tooling and the official style guidance, while still keeping the code tidy and maintainable.

Indentation in Terraform (HCL) is about readability and consistency. The language doesn’t require a specific amount of whitespace for parsing, but the recommended style is two spaces per indentation level. This standard keeps nested blocks and attributes easy to scan and compare across configurations. It also aligns with the formatter Terraform provides (terraform fmt), which outputs code using two-space indentation, reinforcing a uniform look across projects.

Using two spaces per level helps distinguish hierarchy clearly, for example when you have a resource block with nested blocks and multiple attributes. Four spaces, three spaces, or a tab can lead to inconsistent appearance between editors or teams, making reviews slower and increasing the chance of misreadings. So, two spaces is the best-fit choice because it matches common tooling and the official style guidance, while still keeping the code tidy and maintainable.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy