From c6b350b98e39a8fc31bf2ddba27cb58775921126 Mon Sep 17 00:00:00 2001 From: gamename Date: Tue, 1 Mar 2016 17:08:57 -0600 Subject: [PATCH 1/2] docs(variables): describe order of evaluation with files --- .../source/docs/commands/apply.html.markdown | 2 +- .../source/docs/commands/plan.html.markdown | 2 +- .../source/docs/commands/push.html.markdown | 4 +- .../docs/commands/refresh.html.markdown | 3 +- .../docs/configuration/variables.html.md | 82 ++++++++++++++----- 5 files changed, 70 insertions(+), 23 deletions(-) diff --git a/website/source/docs/commands/apply.html.markdown b/website/source/docs/commands/apply.html.markdown index 770d41c95..6f9a35e2f 100644 --- a/website/source/docs/commands/apply.html.markdown +++ b/website/source/docs/commands/apply.html.markdown @@ -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. diff --git a/website/source/docs/commands/plan.html.markdown b/website/source/docs/commands/plan.html.markdown index cf6a78017..ad21e1f30 100644 --- a/website/source/docs/commands/plan.html.markdown +++ b/website/source/docs/commands/plan.html.markdown @@ -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 diff --git a/website/source/docs/commands/push.html.markdown b/website/source/docs/commands/push.html.markdown index f6dda9e64..df1e9615d 100644 --- a/website/source/docs/commands/push.html.markdown +++ b/website/source/docs/commands/push.html.markdown @@ -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 diff --git a/website/source/docs/commands/refresh.html.markdown b/website/source/docs/commands/refresh.html.markdown index 0fc3fc938..10db2d7f9 100644 --- a/website/source/docs/commands/refresh.html.markdown +++ b/website/source/docs/commands/refresh.html.markdown @@ -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. + diff --git a/website/source/docs/configuration/variables.html.md b/website/source/docs/configuration/variables.html.md index 79d4060fa..1062b32bb 100644 --- a/website/source/docs/configuration/variables.html.md +++ b/website/source/docs/configuration/variables.html.md @@ -108,25 +108,6 @@ 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: @@ -149,3 +130,66 @@ VALUE ... } ``` + +## 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 +... +``` + +## Variable Files + +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: + +``` +terraform apply -var-file=foo.tfvars -var-file=bar.tfvars +``` + +**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" +} +``` + +_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. + + From 3bc09db7e0d856a657de7e34412fd3f8c6dab280 Mon Sep 17 00:00:00 2001 From: gamename Date: Tue, 1 Mar 2016 17:13:05 -0600 Subject: [PATCH 2/2] docs(variables): redundant wording --- website/source/docs/commands/push.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/docs/commands/push.html.markdown b/website/source/docs/commands/push.html.markdown index df1e9615d..8b2f59907 100644 --- a/website/source/docs/commands/push.html.markdown +++ b/website/source/docs/commands/push.html.markdown @@ -65,7 +65,7 @@ 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. This flag - can be repeated multiple times. + can be used multiple times. * `-vcs=true` - If true (default), then Terraform will detect if a VCS