github.com/atsaki/terraform@v0.4.3-0.20150919165407-25bba5967654/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    * Numbers are assumed to be base 10. If you prefix a number with
    58      `0x`, it is treated as a hexadecimal number.
    59  
    60    * Numbers can be suffixed with `kKmMgG` for some multiple of 10.
    61      For example: `1k` is equal to `1000`.
    62  
    63    * Numbers can be suffixed with `[kKmMgG]b` for power of 2 multiples,
    64      example: `1kb` is equal to `1024`.
    65  
    66    * Boolean values: `true`, `false`.
    67  
    68    * Lists of primitive types can be made by wrapping it in `[]`.
    69      Example: `["foo", "bar", 42]`.
    70  
    71    * Maps can be made with the `{}` syntax:
    72  	`{ "foo": "bar", "bar": "baz" }`.
    73  
    74  In addition to the basics, the syntax supports hierarchies of sections,
    75  such as the "resource" and "variable" in the example above. These
    76  sections are similar to maps, but visually look better. For example,
    77  these are nearly equivalent:
    78  
    79  ```
    80  variable "ami" {
    81  	description = "the AMI to use"
    82  }
    83  
    84  # is equal to:
    85  
    86  variable = [{
    87  	"ami": {
    88  		"description": "the AMI to use",
    89  	}
    90  }]
    91  ```
    92  
    93  Notice how the top stanza visually looks a lot better? By repeating
    94  multiple `variable` sections, it builds up the `variable` list. When
    95  possible, use sections since they're visually clearer and more readable.
    96  
    97  ## JSON Syntax
    98  
    99  Terraform also supports reading JSON formatted configuration files.
   100  The above example converted to JSON:
   101  
   102  ```json
   103  {
   104  	"variable": {
   105  		"ami": {
   106  			"description": "the AMI to use"
   107  		}
   108  	},
   109  
   110  	"resource": {
   111  		"aws_instance": {
   112  			"web": {
   113  				"ami": "${var.ami}",
   114  				"count": 2,
   115  				"source_dest_check": false,
   116  
   117  				"connection": {
   118  					"user": "root"
   119  				}
   120  			}
   121  		}
   122  	}
   123  }
   124  ```
   125  
   126  The conversion should be pretty straightforward and self-documented.
   127  
   128  The downsides of JSON are less human readability and the lack of
   129  comments. Otherwise, the two are completely interoperable.