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