github.com/hugorut/terraform@v1.1.3/website/docs/cli/config/environment-variables.mdx (about)

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