2015-07-02 04:38:25 +02:00
---
2021-12-15 03:41:17 +01:00
page_title: Environment Variables
description: >-
Learn to use environment variables to change Terraform's default behavior.
Configure log content and output, set variables, and more.
2015-07-02 04:38:25 +02:00
---
# Environment Variables
2018-05-05 22:45:49 +02:00
Terraform refers to a number of environment variables to customize various
aspects of its behavior. None of these environment variables are required
when using Terraform, but they can be used to change some of Terraform's
default behaviors in unusual situations, or to increase output verbosity
for debugging.
2015-07-02 04:38:25 +02:00
## TF_LOG
2020-10-23 14:52:48 +02:00
Enables detailed logs to appear on stderr which is useful for debugging. For example:
2015-07-02 04:38:25 +02:00
2017-04-05 17:29:27 +02:00
```shell
2020-10-23 14:52:48 +02:00
export TF_LOG=trace
2015-07-02 04:38:25 +02:00
```
2020-10-23 14:52:48 +02:00
To disable, either unset it, or set it to `off`. For example:
2015-07-02 04:38:25 +02:00
2017-04-05 17:29:27 +02:00
```shell
2020-10-23 14:52:48 +02:00
export TF_LOG=off
2015-07-02 04:38:25 +02:00
```
2021-12-15 03:41:17 +01:00
For more on debugging Terraform, check out the section on [Debugging](/internals/debugging).
2015-07-02 04:38:25 +02:00
## 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:
2017-04-05 17:29:27 +02:00
```shell
2015-07-02 04:38:25 +02:00
export TF_LOG_PATH=./terraform.log
```
2021-12-15 03:41:17 +01:00
For more on debugging Terraform, check out the section on [Debugging](/internals/debugging).
2015-07-02 04:38:25 +02:00
## 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:
2017-04-05 17:29:27 +02:00
```shell
2015-07-02 04:38:25 +02:00
export TF_INPUT=0
```
## 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:
2017-04-05 17:29:27 +02:00
```shell
2015-07-02 04:38:25 +02:00
export TF_VAR_region=us-west-1
export TF_VAR_ami=ami-049d8641
2016-07-12 00:37:51 +02:00
export TF_VAR_alist='[1,2,3]'
export TF_VAR_amap='{ foo = "bar", baz = "qux" }'
2015-07-02 04:38:25 +02:00
```
2021-12-15 03:41:17 +01:00
For more on how to use `TF_VAR_name` in context, check out the section on [Variable Configuration](/language/values/variables).
2016-01-21 22:44:18 +01:00
2017-02-13 23:51:37 +01:00
## TF_CLI_ARGS and TF_CLI_ARGS_name
2021-12-15 03:41:17 +01:00
2021-07-14 20:08:52 +02:00
<a id="tf-cli-args"></a>
2017-02-13 23:51:37 +01:00
The value of `TF_CLI_ARGS` will specify additional arguments to the
command-line. This allows easier automation in CI environments as well as
modifying default behavior of Terraform on your own system.
These arguments are inserted directly _after_ the subcommand
(such as `plan`) and _before_ any flags specified directly on the command-line.
This behavior ensures that flags on the command-line take precedence over
environment variables.
For example, the following command: `TF_CLI_ARGS="-input=false" terraform apply -force`
is the equivalent to manually typing: `terraform apply -input=false -force`.
The flag `TF_CLI_ARGS` affects all Terraform commands. If you specify a
named command in the form of `TF_CLI_ARGS_name` then it will only affect
that command. As an example, to specify that only plans never refresh,
you can set `TF_CLI_ARGS_plan="-refresh=false"`.
The value of the flag is parsed as if you typed it directly to the shell.
Double and single quotes are allowed to capture strings and arguments will
be separated by spaces otherwise.
2017-11-02 00:44:03 +01:00
## TF_DATA_DIR
`TF_DATA_DIR` changes the location where Terraform keeps its
per-working-directory data, such as the current remote backend configuration.
By default this data is written into a `.terraform` subdirectory of the
current directory, but the path given in `TF_DATA_DIR` will be used instead
if non-empty.
In most cases it should not be necessary to set this variable, but it may
be useful to do so if e.g. the working directory is not writable.
The data directory is used to retain data that must persist from one command
to the next, so it's important to have this variable set consistently throughout
all of the Terraform workflow commands (starting with `terraform init`) or else
Terraform may be unable to find providers, modules, and other artifacts.
2019-01-17 15:24:16 +01:00
## TF_WORKSPACE
For multi-environment deployment, in order to select a workspace, instead of doing `terraform workspace select your_workspace`, it is possible to use this environment variable. Using TF_WORKSPACE allow and override workspace selection.
For example:
```shell
2019-01-18 16:26:42 +01:00
export TF_WORKSPACE=your_workspace
2019-01-17 15:24:16 +01:00
```
Using this environment variable is recommended only for non-interactive usage, since in a local shell environment it can be easy to forget the variable is set and apply changes to the wrong state.
2021-12-15 03:41:17 +01:00
For more information regarding workspaces, check out the section on [Using Workspaces](/language/state/workspaces).
2020-10-13 22:07:28 +02:00
2019-03-21 20:08:56 +01:00
## TF_IN_AUTOMATION
If `TF_IN_AUTOMATION` is set to any non-empty value, Terraform adjusts its
output to avoid suggesting specific commands to run next. This can make the
output more consistent and less confusing in workflows where users don't
directly execute Terraform commands, like in CI systems or other wrapping
applications.
This is a purely cosmetic change to Terraform's human-readable output, and the
exact output differences can change between minor Terraform versions.
2020-10-02 20:02:59 +02:00
For more details, see [Running Terraform in Automation](https://learn.hashicorp.com/tutorials/terraform/automate-terraform?in=terraform/automation&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS).
2019-04-05 20:21:40 +02:00
2020-02-14 20:43:10 +01:00
## TF_REGISTRY_DISCOVERY_RETRY
Set `TF_REGISTRY_DISCOVERY_RETRY` to configure the max number of request retries
the remote registry client will attempt for client connection errors or
500-range responses that are safe to retry.
2020-03-05 17:37:06 +01:00
## TF_REGISTRY_CLIENT_TIMEOUT
The default client timeout for requests to the remote registry is 10s. `TF_REGISTRY_CLIENT_TIMEOUT` can be configured and increased during extraneous circumstances.
```shell
export TF_REGISTRY_CLIENT_TIMEOUT=15
```
2019-04-05 20:21:40 +02:00
## TF_CLI_CONFIG_FILE
2021-12-15 03:41:17 +01:00
The location of the [Terraform CLI configuration file](/cli/config/config-file).
2019-04-05 20:21:40 +02:00
```shell
export TF_CLI_CONFIG_FILE="$HOME/.terraformrc-custom"
```
2020-03-27 06:38:21 +01:00
## TF_IGNORE
2020-05-14 22:35:27 +02:00
If `TF_IGNORE` is set to "trace", Terraform will output debug messages to display ignored files and folders. This is useful when debugging large repositories with `.terraformignore` files.
2020-03-27 06:38:21 +01:00
```shell
export TF_IGNORE=trace
```
2021-12-15 03:41:17 +01:00
For more details on `.terraformignore`, please see [Excluding Files from Upload with .terraformignore](/language/settings/backends/remote#excluding-files-from-upload-with-terraformignore).