github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/website/source/docs/configuration/syntax.html.md (about)

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