github.com/maheshbr/terraform@v0.3.1-0.20141020033300-deec7194a3ea/website/source/docs/configuration/syntax.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Configuration Syntax" 4 sidebar_current: "docs-config-syntax" 5 --- 6 7 # Configuration Syntax 8 9 The syntax of Terraform configurations is custom. It is meant to 10 strike a balance between human readable and editable as well as being 11 machine-friendly. For machine-friendliness, Terraform can also 12 read JSON configurations. For general Terraform configurations, 13 however, we recommend using the Terraform syntax. 14 15 ## Terraform Syntax 16 17 Here is an example of Terraform syntax: 18 19 ``` 20 # An AMI 21 variable "ami" { 22 description = "the AMI to use" 23 } 24 25 /* A multi 26 line comment. */ 27 resource "aws_instance" "web" { 28 ami = "${var.ami}" 29 count = 2 30 source_dest_check = false 31 32 connection { 33 user = "root" 34 } 35 } 36 ``` 37 38 Basic bullet point reference: 39 40 * Single line comments start with `#` 41 42 * Multi-line comments are wrapped with `/*` and `*/` 43 44 * Values are assigned with the syntax of `key = value` (whitespace 45 doesn't matter). The value can be any primitive: a string, 46 number, or boolean. 47 48 * Strings are in double-quotes. 49 50 * Strings can interpolate other values using syntax wrapped 51 in `${}`, such as `${var.foo}`. The full syntax for interpolation 52 is 53 [documented here](/docs/configuration/interpolation.html). 54 55 * Numbers are assumed to be base 10. If you prefix a number with 56 `0x`, it is treated as a hexadecimal number. 57 58 * Numbers can be suffixed with `kKmMgG` for some multiple of 10. 59 For example: `1k` is equal to `1000`. 60 61 * Numbers can be suffxed with `[kKmMgG]b` for power of 2 multiples, 62 example: `1kb` is equal to `1024`. 63 64 * Boolean values: `true`, `false`, `on`, `off`, `yes`, `no`. 65 66 * Arrays of primitive types can be made by wrapping it in `[]`. 67 Example: `["foo", "bar", 42]`. 68 69 * Maps can be made with the `{}` syntax: 70 `{ "foo": "bar", "bar": "baz" }`. 71 72 In addition to the basics, the syntax supports hierarchies of sections, 73 such as the "resource" and "variable" in the example above. These 74 sections are similar to maps, but visually look better. For example, 75 these are nearly equivalent: 76 77 ``` 78 variable "ami" { 79 description = "the AMI to use" 80 } 81 82 # is equal to: 83 84 variable = [{ 85 "ami": { 86 "description": "the AMI to use", 87 } 88 }] 89 ``` 90 91 Notice how the top stanza visually looks a lot better? By repeating 92 multiple `variable` sections, it builds up the `variable` array. When 93 possible, use sections since they're visually clearer and more readable. 94 95 ## JSON Syntax 96 97 Terraform also supports reading JSON formatted configuration files. 98 The above example converted to JSON: 99 100 ```json 101 { 102 "variable": { 103 "ami": { 104 "description": "the AMI to use" 105 } 106 }, 107 108 "resource": { 109 "aws_instance": { 110 "web": { 111 "ami": "${var.ami}", 112 "count": 2, 113 "source_dest_check": false, 114 115 "connection": { 116 "user": "root" 117 } 118 } 119 } 120 } 121 } 122 ``` 123 124 The conversion should be pretty straightforward and self-documented. 125 126 The downsides of JSON are less human readability and the lack of 127 comments. Otherwise, the two are completely interoperable.