TA-002-P · Question #92
If writing Terraform code that adheres to the Terraform style conventions, how would you properly indent each nesting level compared to the one above it?
The correct answer is D. With two spaces. The Terraform style convention specifies two spaces per nesting level, enforced automatically by 'terraform fmt'.
Question
If writing Terraform code that adheres to the Terraform style conventions, how would you properly indent each nesting level compared to the one above it?
Options
- AWith four spaces
- BWith a tab
- CWith three spaces
- DWith two spaces
How the community answered
(35 responses)- A3% (1)
- B9% (3)
- C3% (1)
- D86% (30)
Why each option
The Terraform style convention specifies two spaces per nesting level, enforced automatically by 'terraform fmt'.
Four-space indentation does not conform to the Terraform style convention; 'terraform fmt' will rewrite four-space indented code to two spaces.
Tab characters are explicitly replaced by 'terraform fmt' with two spaces and do not conform to the official Terraform style convention.
Three-space indentation is not specified by any HashiCorp style guide and is not a recognized standard in the Terraform ecosystem.
The HashiCorp Terraform style guide explicitly requires two spaces of indentation for each nesting level relative to its parent block. This convention is enforced by the 'terraform fmt' command, which automatically rewrites configuration files to use two-space indentation and replaces any tabs or other spacing. Consistent two-space indentation improves readability and ensures uniformity across team codebases.
Concept tested: Terraform style convention indentation standard
Source: https://developer.hashicorp.com/terraform/language/style
Topics
Community Discussion
No community discussion yet for this question.