nerdexam
HashiCorp

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.

Read, generate, and modify configuration

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)
  • A
    3% (1)
  • B
    7% (2)
  • C
    87% (26)
  • D
    3% (1)

Why each option

HashiCorp's official Terraform style guide specifies 2 spaces per nesting level for indentation in configuration files.

A0

0 spaces would mean no indentation at all, making nested blocks visually indistinguishable from top-level blocks and violating HashiCorp style conventions.

B1

1 space is not the recommended indentation level; HashiCorp specifies 2 spaces as the standard for readability and consistency.

C2Correct

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.

D4

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

#Terraform formatting#Code style#Indentation#Best practices

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice