nerdexam
HashiCorp

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'.

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

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)
  • A
    3% (1)
  • B
    9% (3)
  • C
    3% (1)
  • D
    86% (30)

Why each option

The Terraform style convention specifies two spaces per nesting level, enforced automatically by 'terraform fmt'.

AWith four spaces

Four-space indentation does not conform to the Terraform style convention; 'terraform fmt' will rewrite four-space indented code to two spaces.

BWith a tab

Tab characters are explicitly replaced by 'terraform fmt' with two spaces and do not conform to the official Terraform style convention.

CWith three spaces

Three-space indentation is not specified by any HashiCorp style guide and is not a recognized standard in the Terraform ecosystem.

DWith two spacesCorrect

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

#Terraform style conventions#Indentation#Code formatting#terraform fmt

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice