HashiCorp Terraform Associate Practice Exam

Access More Questions
When writing Terraform code, how should you indent each nesting level relative to the level above it?
Correct Answer:
With two spaces
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.

Access more questions from this quiz

Continue to HashiCorp Terraform Associate Practice Exam for more practice questions and the full quiz experience.

Access More Questions