Skip to content

Commit

Permalink
docs(variables): describe order of evaluation with files
Browse files Browse the repository at this point in the history
  • Loading branch information
gamename committed Mar 1, 2016
1 parent 986eefc commit c6b350b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 16 deletions.
2 changes: 1 addition & 1 deletion website/source/docs/commands/apply.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ The command-line flags are all optional. The list of available flags are:
* `-var-file=foo` - Set variables in the Terraform configuration from
a file. If "terraform.tfvars" is present, it will be automatically
loaded first. Any files specified by `-var-file` override any values
in a "terraform.tfvars".
in a "terraform.tfvars". This flag can be used multiple times.

2 changes: 1 addition & 1 deletion website/source/docs/commands/plan.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The command-line flags are all optional. The list of available flags are:

* `-var-file=foo` - Set variables in the Terraform configuration from
a file. If "terraform.tfvars" is present, it will be automatically
loaded if this flag is not specified.
loaded if this flag is not specified. This flag can be used multiple times.

## Security Warning

Expand Down
4 changes: 3 additions & 1 deletion website/source/docs/commands/push.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ The command-line flags are all optional. The list of available flags are:

* `-var='foo=bar'` - Set the value of a variable for the Terraform configuration.

* `-var-file=foo` - Set the value of variables using a variable file.
* `-var-file=foo` - Set the value of variables using a variable file. This flag
can be repeated multiple times.


* `-vcs=true` - If true (default), then Terraform will detect if a VCS
is in use, such as Git, and will only upload files that are committed to
Expand Down
3 changes: 2 additions & 1 deletion website/source/docs/commands/refresh.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ The command-line flags are all optional. The list of available flags are:

* `-var-file=foo` - Set variables in the Terraform configuration from
a file. If "terraform.tfvars" is present, it will be automatically
loaded if this flag is not specified.
loaded if this flag is not specified. This flag can be used multiple times.


68 changes: 56 additions & 12 deletions website/source/docs/configuration/variables.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ The usage of maps, strings, etc. is documented fully in the
[interpolation syntax](/docs/configuration/interpolation.html)
page.

## Syntax

The full syntax is:

```
variable NAME {
[type = TYPE]
[default = DEFAULT]
[description = DESCRIPTION]
}
```

where `DEFAULT` is:

```
VALUE
{
KEY = VALUE
...
}
```

## Environment Variables

Environment variables can be used to set the value of a variable.
Expand All @@ -127,25 +150,46 @@ $ TF_VAR_image=foo terraform apply
...
```

## Syntax
## Variable Files

The full syntax is:
Variables can be collected in files and passed all at once using the
`-var-file=foo` flag.

The flag can be used multiple times per command invocation:

```
variable NAME {
[type = TYPE]
[default = DEFAULT]
[description = DESCRIPTION]
}
terraform apply -var-file=foo.tfvars -var-file=bar.tfvars
```

where `DEFAULT` is:
**Note** If a variable is defined in more than one file passed, the last
variable file (reading left to right) will be the definition used. Put more
simply, the last time a variable is defined is the one which will be used.

##Example:

Both these files have the variable `baz` defined:

_foo.tfvars_
```
variable "baz" {
default = "foo"
}
```
VALUE

{
KEY = VALUE
...
_bar.tfvars_
```
variable "baz" {
default = "bar"
}
```

When they are passed in the following order:

```
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.


0 comments on commit c6b350b

Please sign in to comment.