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