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 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:
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.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Eltooth
Highly Voted 2 years, 4 months agoPower123
Most Recent 1 year, 7 months agoaone
1 year, 8 months agozecch
1 year, 8 months agoAbhijeet2904
1 year, 9 months agoDavid_C_90
1 year, 8 months agoalen995454
10 months, 2 weeks agovadeemkaa
1 year, 11 months ago