Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - 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?

Show Answer
Correct Answer: D

When writing Terraform code that adheres to the Terraform style conventions, each nesting level should be indented two spaces compared to the level above it. This standard helps ensure consistency and readability in the code. Adhering to this convention allows Terraform files to be easily readable and manageable across different teams and projects.

Discussion

6 comments
Sign in to comment
EltoothOption: D
Jan 7, 2023

D is correct answer: Indent two spaces for each nesting level. https://www.terraform.io/language/syntax/style#style-conventions

vadeemkaa
Jun 22, 2023

Answer D for sure

Abhijeet2904Option: A
Aug 6, 2023

A. With four spaces When writing Terraform code that adheres to the Terraform style conventions, each nesting level should be indented four spaces compared to the level above it. This helps to visually distinguish between different levels of nesting and improves readability of the code. In Terraform, a common use case for nested blocks is to define resources that depend on other resources. For example, you might have a resource that creates a network security group, and then another resource that creates a virtual machine that references the network security group. In this case, the virtual machine resource would be indented four spaces compared to the network security group resource. Using four spaces for indentation is a widely accepted standard in the software development community, and it is recommended to use four spaces for indentation in Terraform code as well.

David_C_90
Sep 15, 2023

dont paste chat gpt answers

alen995454
Jul 13, 2024

"Compared to one above" .. not the parent

zecch
Sep 8, 2023

definitely D

aone
Sep 22, 2023

The Terraform parser allows you some flexibility in how you lay out the elements in your configuration files, but the Terraform language also has some idiomatic style conventions which we recommend users always follow for consistency between files and modules written by different teams. Automatic source code formatting tools may apply these conventions automatically. Note: You can enforce these conventions automatically by running terraform fmt. Indent two spaces for each nesting level. When multiple arguments with single-line values appear on consecutive lines at the same nesting level, align their equals signs:

Power123
Sep 30, 2023

2 spaces. Answer is D