diff --git a/website/source/docs/configuration/variables.html.md b/website/source/docs/configuration/variables.html.md index 4e8b834e83..3f4c2caa7b 100644 --- a/website/source/docs/configuration/variables.html.md +++ b/website/source/docs/configuration/variables.html.md @@ -90,6 +90,25 @@ The usage of maps, strings, etc. is documented fully in the [interpolation syntax](/docs/configuration/interpolation.html) 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 The full syntax is: diff --git a/website/source/intro/getting-started/variables.html.md b/website/source/intro/getting-started/variables.html.md index 2ab525b8bb..935769f517 100644 --- a/website/source/intro/getting-started/variables.html.md +++ b/website/source/intro/getting-started/variables.html.md @@ -53,14 +53,16 @@ the AWS provider with the given 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. These variables are not saved, but provides a nice user experience for 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 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 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 "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 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 version control.