From b4ca04cb780f407eac90925aeedf93ea05c472f6 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Wed, 1 Jul 2015 13:11:21 -0500 Subject: [PATCH 01/27] docs: expand how to assign mappings from file --- .../intro/getting-started/variables.html.md | 51 +++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/website/source/intro/getting-started/variables.html.md b/website/source/intro/getting-started/variables.html.md index 935769f517..691c91f385 100644 --- a/website/source/intro/getting-started/variables.html.md +++ b/website/source/intro/getting-started/variables.html.md @@ -98,6 +98,7 @@ 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. + ## Mappings We've replaced our sensitive strings with variables, but we still @@ -140,15 +141,59 @@ While we don't use it in our example, it is worth noting that you can also do a static lookup of a mapping directly with `${var.amis.us-east-1}`. -We set defaults, but mappings can also be overridden using the -`-var` and `-var-file` values. For example, if the user wanted to -specify an alternate AMI for us-east-1: + +## Assigning Mappings + +We set defaults above, but mappings can also be set using the `-var` and +`-var-file` values. For example, if the user wanted to specify an alternate AMI +for us-east-1: ``` $ terraform plan -var 'amis.us-east-1=foo' ... ``` +**Note**: even if every key will be assigned as input, the variable must be +established as a mapping by setting its default to `{}`. + +Here is an example of setting a mapping's keys from a file. Starting with these +variable definitions: + +``` +variable "region" {} +variable "amis" { + default = {} +} +``` + +You can specify keys in a `terraform.tfvars` file: + +``` +amis.us-east-1 = "ami-abc123" +amis.us-west-2 = "ami-def456" +``` + +And access them via `lookup()`: + +``` +output "ami" { + value = "${lookup(var.amis, var.region)} +} +``` + +Like so: + +``` +$ terraform apply -var region=us-west-2 + +Apply complete! Resources: 0 added, 0 changed, 0 destroyed. + +Outputs: + + ami = ami-def456 + +``` + ## Next Terraform provides variables for parameterizing your configurations. From 382cad03c28a0c206f4dbb9bbaf23cdf655d6a43 Mon Sep 17 00:00:00 2001 From: Nathaniel Schweinberg Date: Wed, 1 Jul 2015 21:38:25 -0500 Subject: [PATCH 02/27] Added page documenting useful Environment Variables --- .../environment-variables.html.md | 64 +++++++++++++++++++ website/source/layouts/docs.erb | 4 ++ 2 files changed, 68 insertions(+) create mode 100644 website/source/docs/configuration/environment-variables.html.md diff --git a/website/source/docs/configuration/environment-variables.html.md b/website/source/docs/configuration/environment-variables.html.md new file mode 100644 index 0000000000..60b426b357 --- /dev/null +++ b/website/source/docs/configuration/environment-variables.html.md @@ -0,0 +1,64 @@ +--- +layout: "docs" +page_title: "Environment Variables" +sidebar_current: "docs-config-environment-variables" +description: |- + Something on Environment Variables! +--- + +# Environment Variables + +## TF_LOG + +If set to any value, enables detailed logs to appear on stderr which is useful for debugging. For example: + +``` +export TF_LOG=1 +``` + +To disable, either unset it or set it to empty. For example: + +``` +export TF_LOG= +``` + +For more on debugging Terraform, check out the section on [Debugging](/docs/internals/debugging.html). + +## TF_LOG_PATH + +This specifies where the log should persist its output to. Note that even when `TF_LOG_PATH` is set, `TF_LOG` must be set in order for any logging to be enabled. For example, to always write the log to the directory you're currently running terraform from: + +``` +export TF_LOG_PATH=./terraform.log +``` + +For more on debugging Terraform, check out the section on [Debugging](/docs/internals/debugging.html). + +## TF_INPUT + +If set to "false" or "0", causes terraform commands to behave as if the `-input=false` flag was specified. This is used when you want to disable prompts for variables that haven't had their values specified. For example: + +``` +export TF_INPUT=0 +``` + +## TF_MODULE_DEPTH + +When given a value, causes terraform commands to behave as if the `-module=depth=VALUE` flag was specified. Modules are treated like a black box and terraform commands do not show what resources within the module will be created. By setting this to -1, for example, you enable commands such as [plan](/docs/commands/plan.html) and [graph](/docs/commands/graph.html) to display more detailed information. + +``` +export TF_MODULE_DEPTH=-1 +``` + +For more information regarding modules, check out the section on [Using Modules](/docs/modules/usage.html). + +## TF_VAR_name + +Environment variables can be used to set variables. The environment variables must be in the format `TF_VAR_name` and this will be checked last for a value. For example: + +``` +export TF_VAR_region=us-west-1 +export TF_VAR_ami=ami-049d8641 +``` + +For more on how to use `TF_VAR_name` in context, check out the section on [Variable Configuration](/docs/configuration/variables.html). diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index dbbf87b8ad..ef69a86d16 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -49,6 +49,10 @@ Atlas + > + Environment Variables + + From 80d77df477456e4abe98dd8b2b1f683a879c0650 Mon Sep 17 00:00:00 2001 From: Nathaniel Schweinberg Date: Wed, 1 Jul 2015 21:40:04 -0500 Subject: [PATCH 03/27] fixed indentation --- website/source/layouts/docs.erb | 432 ++++++++++++++++---------------- 1 file changed, 216 insertions(+), 216 deletions(-) diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index ef69a86d16..da123e74e4 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -1,266 +1,266 @@ <% wrap_layout :inner do %> - <% content_for :sidebar do %> - + <% end %> - <%= yield %> - <% end %> + <%= yield %> + <% end %> From d857746d49a9a179b59810c9b1578b051148905d Mon Sep 17 00:00:00 2001 From: Nathaniel Schweinberg Date: Wed, 1 Jul 2015 21:46:51 -0500 Subject: [PATCH 04/27] tweaking indentation settings --- website/source/layouts/docs.erb | 406 ++++++++++++++++---------------- 1 file changed, 203 insertions(+), 203 deletions(-) diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index da123e74e4..3bcb156549 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -1,266 +1,266 @@ <% wrap_layout :inner do %> - <% content_for :sidebar do %> - + <% end %> - <%= yield %> - <% end %> + <%= yield %> + <% end %> From e38ced77854ad18c3e84d9d099699c5125241f94 Mon Sep 17 00:00:00 2001 From: Nathaniel Schweinberg Date: Wed, 1 Jul 2015 21:48:25 -0500 Subject: [PATCH 05/27] retabd --- website/source/layouts/docs.erb | 420 ++++++++++++++++---------------- 1 file changed, 210 insertions(+), 210 deletions(-) diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index 3bcb156549..f965d2ab62 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -1,266 +1,266 @@ <% wrap_layout :inner do %> - <% content_for :sidebar do %> - + <% end %> - <%= yield %> - <% end %> + <%= yield %> + <% end %> From 03554ec8ca132e3978b0488d98e48954c62f6719 Mon Sep 17 00:00:00 2001 From: Nathaniel Schweinberg Date: Wed, 1 Jul 2015 21:50:26 -0500 Subject: [PATCH 06/27] fixed formatting glitches --- website/source/layouts/docs.erb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index f965d2ab62..6e650eb185 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -85,7 +85,7 @@ > plan - + > push @@ -93,7 +93,7 @@ > refresh - + > remote @@ -120,10 +120,10 @@ > Providers -