diff --git a/main.go b/main.go index 8caf7414b..c93407805 100644 --- a/main.go +++ b/main.go @@ -231,7 +231,12 @@ func wrappedMain() int { func cliConfigFile() (string, error) { mustExist := true - configFilePath := os.Getenv("TERRAFORM_CONFIG") + + configFilePath := os.Getenv("TF_CLI_CONFIG_FILE") + if configFilePath == "" { + configFilePath = os.Getenv("TERRAFORM_CONFIG") + } + if configFilePath == "" { var err error configFilePath, err = ConfigFile() diff --git a/website/docs/commands/cli-config.html.markdown b/website/docs/commands/cli-config.html.markdown index 7f26ed0a0..5687f26d1 100644 --- a/website/docs/commands/cli-config.html.markdown +++ b/website/docs/commands/cli-config.html.markdown @@ -32,6 +32,9 @@ CLI configuration file, even though Windows Explorer may _display_ its name as just `terraform.rc`. Use `dir` from PowerShell or Command Prompt to confirm the filename. +The location of the Terraform CLI configuration file can also be specified +using the `TF_CLI_CONFIG_FILE` [environment variable](/docs/commands/environment-variables.html). + ## Configuration File Syntax The configuration file uses the same _HCL_ syntax as `.tf` files, but with diff --git a/website/docs/commands/environment-variables.html.md b/website/docs/commands/environment-variables.html.md index a8cd3f7d9..c163dc625 100644 --- a/website/docs/commands/environment-variables.html.md +++ b/website/docs/commands/environment-variables.html.md @@ -113,3 +113,11 @@ This is a purely cosmetic change to Terraform's human-readable output, and the exact output differences can change between minor Terraform versions. For more details see [Running Terraform in Automation](https://learn.hashicorp.com/terraform/development/running-terraform-in-automation). + +## TF_CLI_CONFIG_FILE + +The location of the [Terraform CLI configuration file](/docs/commands/cli-config.html). + +```shell +export TF_CLI_CONFIG_FILE="$HOME/.terraformrc-custom" +```