github.com/bengesoff/terraform@v0.3.1-0.20141018223233-b25a53629922/website/source/docs/configuration/variables.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Configuring Variables" 4 sidebar_current: "docs-config-variables" 5 --- 6 7 # Variable Configuration 8 9 Variables define the parameterization of Terraform configurations. 10 Variables can be overridden via the CLI. Variable usage is 11 covered in more detail in the 12 [getting started guide](/intro/getting-started/variables.html). 13 This page covers configuration syntax for variables. 14 15 This page assumes you're familiar with the 16 [configuration syntax](/docs/configuration/syntax.html) 17 already. 18 19 ## Example 20 21 A variable configuration looks like the following: 22 23 ``` 24 variable "key" {} 25 26 variable "images" { 27 default = { 28 us-east-1 = "image-1234" 29 us-west-2 = "image-4567" 30 } 31 } 32 ``` 33 34 ## Description 35 36 The `variable` block configures a single input variable for 37 a Terraform configuration. Multiple variables blocks can be used to 38 add multiple variables. 39 40 The `NAME` given to the variable block is the name used to 41 set the variable via the CLI as well as reference the variable 42 throughout the Terraform configuration. 43 44 Within the block (the `{ }`) is configuration for the variable. 45 These are the parameters that can be set: 46 47 * `default` (optional) - If set, this sets a default value 48 for the variable. If this isn't set, the variable is required 49 and Terraform will error if not set. The default value can be 50 a string or a mapping. This is covered in more detail below. 51 52 * `description` (optional) - A human-friendly description for 53 the variable. This is primarily for documentation for users 54 using your Terraform configuration. A future version of Terraform 55 will expose these descriptions as part of some Terraform CLI 56 command. 57 58 ------ 59 60 **Default values** can be either strings or maps. If a default 61 value is omitted and the variable is required, the value assigned 62 via the CLI must be a string. 63 64 String values are simple and represent a basic key to value 65 mapping where the key is the variable name. An example is: 66 67 ``` 68 variable "key" { 69 default = "value" 70 } 71 ``` 72 73 A map allows a key to contain a lookup table. This is useful 74 for some values that change depending on some external pivot. 75 A common use case for this is mapping cloud images to regions. 76 An example: 77 78 ``` 79 variable "images" { 80 default = { 81 us-east-1 = "image-1234" 82 us-west-2 = "image-4567" 83 } 84 } 85 ``` 86 87 The usage of maps, strings, etc. is documented fully in the 88 [interpolation syntax](/docs/configuration/interpolation.html) 89 page. 90 91 ## Syntax 92 93 The full syntax is: 94 95 ``` 96 variable NAME { 97 [default = DEFAULT] 98 [description = DESCRIPTION] 99 } 100 ``` 101 102 where `DEFAULT` is: 103 104 ``` 105 VALUE 106 107 { 108 KEY = VALUE 109 ... 110 } 111 ```