github.com/pmcatominey/terraform@v0.7.0-rc2.0.20160708105029-1401a52a5cc5/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 `<<EOF` and then the
    59      string ending with `EOF` 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      Quotes may be omitted on keys, unless the key starts with a number,
    79      in which case quotes are required.
    80  
    81  In addition to the basics, the syntax supports hierarchies of sections,
    82  such as the "resource" and "variable" in the example above. These
    83  sections are similar to maps, but visually look better. For example,
    84  these are nearly equivalent:
    85  
    86  ```
    87  variable "ami" {
    88  	description = "the AMI to use"
    89  }
    90  
    91  # is equal to:
    92  
    93  variable = [{
    94  	"ami": {
    95  		"description": "the AMI to use",
    96  	}
    97  }]
    98  ```
    99  
   100  Notice how the top stanza visually looks a lot better? By repeating
   101  multiple `variable` sections, it builds up the `variable` list. When
   102  possible, use sections since they're visually clearer and more readable.
   103  
   104  ## JSON Syntax
   105  
   106  Terraform also supports reading JSON formatted configuration files.
   107  The above example converted to JSON:
   108  
   109  ```json
   110  {
   111  	"variable": {
   112  		"ami": {
   113  			"description": "the AMI to use"
   114  		}
   115  	},
   116  
   117  	"resource": {
   118  		"aws_instance": {
   119  			"web": {
   120  				"ami": "${var.ami}",
   121  				"count": 2,
   122  				"source_dest_check": false,
   123  
   124  				"connection": {
   125  					"user": "root"
   126  				}
   127  			}
   128  		}
   129  	}
   130  }
   131  ```
   132  
   133  The conversion should be pretty straightforward and self-documented.
   134  
   135  The downsides of JSON are less human readability and the lack of
   136  comments. Otherwise, the two are completely interoperable.