github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/commands/environment-variables.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Environment Variables" 4 sidebar_current: "docs-commands-environment-variables" 5 description: |- 6 Terraform uses environment variables to configure various aspects of its behavior. 7 --- 8 9 # Environment Variables 10 11 Terraform refers to a number of environment variables to customize various 12 aspects of its behavior. None of these environment variables are required 13 when using Terraform, but they can be used to change some of Terraform's 14 default behaviors in unusual situations, or to increase output verbosity 15 for debugging. 16 17 ## TF_LOG 18 19 If set to any value, enables detailed logs to appear on stderr which is useful for debugging. For example: 20 21 ```shell 22 export TF_LOG=TRACE 23 ``` 24 25 To disable, either unset it or set it to empty. When unset, logging will default to stderr. For example: 26 27 ```shell 28 export TF_LOG= 29 ``` 30 31 For more on debugging Terraform, check out the section on [Debugging](/docs/internals/debugging.html). 32 33 ## TF_LOG_PATH 34 35 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: 36 37 ```shell 38 export TF_LOG_PATH=./terraform.log 39 ``` 40 41 For more on debugging Terraform, check out the section on [Debugging](/docs/internals/debugging.html). 42 43 ## TF_INPUT 44 45 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: 46 47 ```shell 48 export TF_INPUT=0 49 ``` 50 51 ## TF_VAR_name 52 53 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: 54 55 ```shell 56 export TF_VAR_region=us-west-1 57 export TF_VAR_ami=ami-049d8641 58 export TF_VAR_alist='[1,2,3]' 59 export TF_VAR_amap='{ foo = "bar", baz = "qux" }' 60 ``` 61 62 For more on how to use `TF_VAR_name` in context, check out the section on [Variable Configuration](/docs/configuration/variables.html). 63 64 ## TF_CLI_ARGS and TF_CLI_ARGS_name 65 66 The value of `TF_CLI_ARGS` will specify additional arguments to the 67 command-line. This allows easier automation in CI environments as well as 68 modifying default behavior of Terraform on your own system. 69 70 These arguments are inserted directly _after_ the subcommand 71 (such as `plan`) and _before_ any flags specified directly on the command-line. 72 This behavior ensures that flags on the command-line take precedence over 73 environment variables. 74 75 For example, the following command: `TF_CLI_ARGS="-input=false" terraform apply -force` 76 is the equivalent to manually typing: `terraform apply -input=false -force`. 77 78 The flag `TF_CLI_ARGS` affects all Terraform commands. If you specify a 79 named command in the form of `TF_CLI_ARGS_name` then it will only affect 80 that command. As an example, to specify that only plans never refresh, 81 you can set `TF_CLI_ARGS_plan="-refresh=false"`. 82 83 The value of the flag is parsed as if you typed it directly to the shell. 84 Double and single quotes are allowed to capture strings and arguments will 85 be separated by spaces otherwise. 86 87 ## TF_DATA_DIR 88 89 `TF_DATA_DIR` changes the location where Terraform keeps its 90 per-working-directory data, such as the current remote backend configuration. 91 92 By default this data is written into a `.terraform` subdirectory of the 93 current directory, but the path given in `TF_DATA_DIR` will be used instead 94 if non-empty. 95 96 In most cases it should not be necessary to set this variable, but it may 97 be useful to do so if e.g. the working directory is not writable. 98 99 The data directory is used to retain data that must persist from one command 100 to the next, so it's important to have this variable set consistently throughout 101 all of the Terraform workflow commands (starting with `terraform init`) or else 102 Terraform may be unable to find providers, modules, and other artifacts. 103 104 ## TF_IN_AUTOMATION 105 106 If `TF_IN_AUTOMATION` is set to any non-empty value, Terraform adjusts its 107 output to avoid suggesting specific commands to run next. This can make the 108 output more consistent and less confusing in workflows where users don't 109 directly execute Terraform commands, like in CI systems or other wrapping 110 applications. 111 112 This is a purely cosmetic change to Terraform's human-readable output, and the 113 exact output differences can change between minor Terraform versions. 114 115 For more details see [Running Terraform in Automation](https://learn.hashicorp.com/terraform/development/running-terraform-in-automation). 116 117 ## TF_REGISTRY_DISCOVERY_RETRY 118 119 Set `TF_REGISTRY_DISCOVERY_RETRY` to configure the max number of request retries 120 the remote registry client will attempt for client connection errors or 121 500-range responses that are safe to retry. 122 123 ## TF_REGISTRY_CLIENT_TIMEOUT 124 125 The default client timeout for requests to the remote registry is 10s. `TF_REGISTRY_CLIENT_TIMEOUT` can be configured and increased during extraneous circumstances. 126 127 ```shell 128 export TF_REGISTRY_CLIENT_TIMEOUT=15 129 ``` 130 131 ## TF_CLI_CONFIG_FILE 132 133 The location of the [Terraform CLI configuration file](/docs/commands/cli-config.html). 134 135 ```shell 136 export TF_CLI_CONFIG_FILE="$HOME/.terraformrc-custom" 137 ```