TA-002-P · Question #243
When writing Terraform code, HashiCorp recommends that you use how many spaces between each nesting level?
The correct answer is C. 2. HashiCorp's official Terraform style guide specifies 2 spaces per nesting level for indentation in configuration files.
Question
When writing Terraform code, HashiCorp recommends that you use how many spaces between each nesting level?
Options
- A0
- B1
- C2
- D4
How the community answered
(30 responses)- A3% (1)
- B7% (2)
- C87% (26)
- D3% (1)
Why each option
HashiCorp's official Terraform style guide specifies 2 spaces per nesting level for indentation in configuration files.
0 spaces would mean no indentation at all, making nested blocks visually indistinguishable from top-level blocks and violating HashiCorp style conventions.
1 space is not the recommended indentation level; HashiCorp specifies 2 spaces as the standard for readability and consistency.
The HashiCorp Terraform style conventions explicitly recommend 2 spaces for each level of nesting within blocks. This applies to resource, variable, output, and all other block types, and `terraform fmt` enforces this standard automatically when formatting code.
4 spaces is a common convention in other languages like Python, but Terraform's official style guide specifies 2 spaces, not 4.
Concept tested: HashiCorp Terraform style guide indentation standard
Source: https://developer.hashicorp.com/terraform/language/style#indentation-and-formatting
Topics
Community Discussion
No community discussion yet for this question.