--- layout: "language" page_title: "Input Variables - 0.11 Configuration Language" sidebar_current: "docs-conf-old-variables" description: |- Input variables are parameters for Terraform modules. This page covers configuration syntax for variables. --- # Input Variables -> **Note:** This page is about Terraform 0.11 and earlier. For Terraform 0.12 and later, see [Configuration Language: Input Variables](../configuration/variables.html). Input variables serve as parameters for a Terraform module. When used in the root module of a configuration, variables can be set from CLI arguments and environment variables. For [_child_ modules](./modules.html), they allow values to pass from parent to child. This page assumes you're familiar with the [configuration syntax](./syntax.html) already. ## Example Input variables can be defined as follows: ```hcl variable "key" { type = "string" } variable "images" { type = "map" default = { us-east-1 = "image-1234" us-west-2 = "image-4567" } } variable "zones" { type = "list" default = ["us-east-1a", "us-east-1b"] } ``` ## Description The `variable` block configures a single input variable for a Terraform module. Each block declares a single variable. The name given in the block header is used to assign a value to the variable via the CLI and to reference the variable elsewhere in the configuration. Within the block body (between `{ }`) is configuration for the variable, which accepts the following arguments: - `type` (Optional) - If set this defines the type of the variable. Valid values are `string`, `list`, and `map`. If this field is omitted, the variable type will be inferred based on `default`. If no `default` is provided, the type is assumed to be `string`. - `default` (Optional) - This sets a default value for the variable. If no default is provided, Terraform will raise an error if a value is not provided by the caller. The default value can be of any of the supported data types, as described below. If `type` is also set, the given value must be of the specified type. - `description` (Optional) - A human-friendly description for the variable. This is primarily for documentation for users using your Terraform configuration. When a module is published in [Terraform Registry](https://registry.terraform.io/), the given description is shown as part of the documentation. The name of a variable can be any valid identifier. However, due to the interpretation of [module configuration blocks](./modules.html), the names `source`, `version` and `providers` are reserved for Terraform's own use and are thus not recommended for any module intended to be used as a child module. The default value of an input variable must be a _literal_ value, containing no interpolation expressions. To assign a name to an expression so that it may be re-used within a module, use [Local Values](./locals.html) instead. ### Strings String values are simple and represent a basic key to value mapping where the key is the variable name. An example is: ```hcl variable "key" { type = "string" default = "value" } ``` A multi-line string value can be provided using heredoc syntax. ```hcl variable "long_key" { type = "string" default = < **Note**: Variable files are evaluated in the order in which they are specified on the command line. If a particular variable is defined in more than one variable file, the last value specified is effective. ### Variable Merging When multiple values are provided for the same input variable, map values are merged while all other values are overridden by the last definition. For example, if you define a variable twice on the command line: ```shell $ terraform apply -var foo=bar -var foo=baz ``` Then the value of `foo` will be `baz`, since it was the last definition seen. However, for maps, the values are merged: ```shell $ terraform apply -var 'foo={quux="bar"}' -var 'foo={bar="baz"}' ``` The resulting value of `foo` will be: ```shell { quux = "bar" bar = "baz" } ``` There is no way currently to unset map values in Terraform. Whenever a map is modified either via variable input or being passed into a module, the values are always merged. ### Variable Precedence Both these files have the variable `baz` defined: _foo.tfvars_ ```hcl baz = "foo" ``` _bar.tfvars_ ```hcl baz = "bar" ``` When they are passed in the following order: ```shell $ terraform apply -var-file=foo.tfvars -var-file=bar.tfvars ``` The result will be that `baz` will contain the value `bar` because `bar.tfvars` has the last definition loaded. Definition files passed using the `-var-file` flag will always be evaluated after those in the working directory. Values passed within definition files or with `-var` will take precedence over `TF_VAR_` environment variables, as environment variables are considered defaults.