website: update docs with environment variables for vars

This commit is contained in:
Mitchell Hashimoto 2015-04-22 06:37:03 +02:00
parent 5ae9ee4d27
commit 316afd8964
2 changed files with 29 additions and 4 deletions

View File

@ -90,6 +90,25 @@ The usage of maps, strings, etc. is documented fully in the
[interpolation syntax](/docs/configuration/interpolation.html) [interpolation syntax](/docs/configuration/interpolation.html)
page. page.
## Environment Variables
Environment variables can be used to set the value of a variable.
The key of the environment variable must be `TF_VAR_name` and the value
is the value of the variable.
For example, given the configuration below:
```
variable "image" {}
```
The variable can be set via an environment variable:
```
$ TF_VAR_image=foo terraform apply
...
```
## Syntax ## Syntax
The full syntax is: The full syntax is:

View File

@ -53,14 +53,16 @@ the AWS provider with the given variables.
## Assigning Variables ## Assigning Variables
There are three ways to assign variables. There are multiple ways to assign variables. Below is also the order
in which variable values are chosen. If they're found in an option first
below, then the options below are ignored.
First, if you execute `terraform plan` or apply without doing **UI Input:** If you execute `terraform plan` or apply without doing
anything, Terraform will ask you to input the variables interactively. anything, Terraform will ask you to input the variables interactively.
These variables are not saved, but provides a nice user experience for These variables are not saved, but provides a nice user experience for
getting started with Terraform. getting started with Terraform.
For another option, you can set it directly on the command-line with the **Command-line flags:** You can set it directly on the command-line with the
`-var` flag. Any command in Terraform that inspects the configuration `-var` flag. Any command in Terraform that inspects the configuration
accepts this flag, such as `apply`, `plan`, and `refresh`: accepts this flag, such as `apply`, `plan`, and `refresh`:
@ -74,7 +76,7 @@ $ terraform plan \
Once again, setting variables this way will not save them, and they'll Once again, setting variables this way will not save them, and they'll
have to be input repeatedly as commands are executed. have to be input repeatedly as commands are executed.
The third way, and the way to persist variable values, is to create **From a file:** To persist variable values, create
a file and assign variables within this file. Create a file named a file and assign variables within this file. Create a file named
"terraform.tfvars" with the following contents: "terraform.tfvars" with the following contents:
@ -89,6 +91,10 @@ named something else, you can use the `-var-file` flag directly to
specify a file. These files are the same syntax as Terraform configuration specify a file. These files are the same syntax as Terraform configuration
files. And like Terraform configuration files, these files can also be JSON. files. And like Terraform configuration files, these files can also be JSON.
**From environment variables:** Terraform will read environment variables
in the form of `TF_VAR_name` to find the value for a variable. For example,
the `TF_VAR_access_key` variable can be set to set the `access_key` variable.
We recommend using the "terraform.tfvars" file, and ignoring it from We recommend using the "terraform.tfvars" file, and ignoring it from
version control. version control.