When writing Terraform code, how should you indent each nesting level relative to the level above it?

Prepare for the HashiCorp Terraform Associate Exam. Utilize flashcards and multiple-choice questions with detailed hints and explanations. Boost your confidence and be ready for success!

Multiple Choice

When writing Terraform code, how should you indent each nesting level relative to the level above it?

Explanation:
In Terraform's HCL, indent each nesting level by two spaces. This means the first level inside a block uses two spaces, the next level uses four spaces, and so on. Using two spaces per level keeps code readable and aligns with the official style shown in examples, and avoids the inconsistencies that can come from tabs or other indentation amounts. For example: resource "aws_instance" "web" { ami = "ami-12345678" instance_type = "t2.micro" network_interface { device_index = 0 } } Here, top-level lines inside the resource start with two spaces; the nested block inside has four spaces, showing the two-space-per-level rule. Tabs are discouraged because their width can vary between editors, and options like three or four spaces per level aren’t the standard in Terraform.

In Terraform's HCL, indent each nesting level by two spaces. This means the first level inside a block uses two spaces, the next level uses four spaces, and so on. Using two spaces per level keeps code readable and aligns with the official style shown in examples, and avoids the inconsistencies that can come from tabs or other indentation amounts.

For example:

resource "aws_instance" "web" {

ami = "ami-12345678"

instance_type = "t2.micro"

network_interface {

device_index = 0

}

}

Here, top-level lines inside the resource start with two spaces; the nested block inside has four spaces, showing the two-space-per-level rule.

Tabs are discouraged because their width can vary between editors, and options like three or four spaces per level aren’t the standard in Terraform.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy