github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/website/docs/language/syntax/style.html.md (about)

     1  ---
     2  layout: "language"
     3  page_title: "Style Conventions - Configuration Language"
     4  sidebar_current: "docs-config-style"
     5  description: |-
     6    Recommended formatting conventions for the Terraform language.
     7  ---
     8  
     9  # Style Conventions
    10  
    11  The Terraform parser allows you some flexibility in how you lay out the
    12  elements in your configuration files, but the Terraform language also has some
    13  idiomatic style conventions which we recommend users always follow
    14  for consistency between files and modules written by different teams.
    15  Automatic source code formatting tools may apply these conventions
    16  automatically.
    17  
    18  * Indent two spaces for each nesting level.
    19  
    20  * When multiple arguments with single-line values appear on consecutive lines
    21    at the same nesting level, align their equals signs:
    22  
    23      ```hcl
    24      ami           = "abc123"
    25      instance_type = "t2.micro"
    26      ```
    27  
    28  * When both arguments and blocks appear together inside a block body,
    29    place all of the arguments together at the top and then place nested
    30    blocks below them. Use one blank line to separate the arguments from
    31    the blocks.
    32  
    33  * Use empty lines to separate logical groups of arguments within a block.
    34  
    35  * For blocks that contain both arguments and "meta-arguments" (as defined by
    36    the Terraform language semantics), list meta-arguments first
    37    and separate them from other arguments with one blank line. Place
    38    meta-argument blocks _last_ and separate them from other blocks with
    39    one blank line.
    40  
    41      ```hcl
    42      resource "aws_instance" "example" {
    43        count = 2 # meta-argument first
    44  
    45        ami           = "abc123"
    46        instance_type = "t2.micro"
    47  
    48        network_interface {
    49          # ...
    50        }
    51  
    52        lifecycle { # meta-argument block last
    53          create_before_destroy = true
    54        }
    55      }
    56      ```
    57  
    58  * Top-level blocks should always be separated from one another by one
    59    blank line. Nested blocks should also be separated by blank lines, except
    60    when grouping together related blocks of the same type (like multiple
    61    `provisioner` blocks in a resource).
    62  
    63  * Avoid separating multiple blocks of the same type with other blocks of
    64    a different type, unless the block types are defined by semantics to
    65    form a family.
    66    (For example: `root_block_device`, `ebs_block_device` and
    67    `ephemeral_block_device` on `aws_instance` form a family of block types
    68    describing AWS block devices, and can therefore be grouped together and
    69    mixed.)
    70