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