-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Improve user feedback about 'bad' values of TF_CLI_CONFIG_FILE environment variable #32646
Description
Terraform Version
Terraform v1.3.5-dev
on darwin_arm64
+ provider registry.terraform.io/hashicorp/google v4.51.0Terraform Configuration Files
Any config is relevant to this issue.
Here I've included the one I used to generate the debug output, but the config's contents are not specific to this issue.
More importantly, here's the CLI config file that I use in this issue:
provider_installation {
dev_overrides {
"hashicorp/google" = "/Users/sarahfrench/go/bin"
"hashicorp/google-beta" = "/Users/sarahfrench/go/bin"
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.0"
}
}
}
provider "google" {
project = var.gcp_project_id
region = var.default_region
zone = var.default_zone
}
variable "gcp_project_id" {
type = string
}
variable "default_region" {
type = string
}
variable "default_zone" {
type = string
}
resource "google_cloud_scheduler_job" "job" {
name = "tf-test-my-example-job"
description = "This is a test cloud scheduler job"
schedule = "*/8 * * * *"
time_zone = "America/New_York"
attempt_deadline = "320s"
retry_config {
retry_count = 1
}
http_target {
http_method = "POST"
uri = "https://example.com/ping"
body = base64encode("{\"foo\":\"bar\"}")
}
}
Debug Output
In these examples I am trying to use a CLI configuration file to use dev_overrides, and I set the path to the file via TF_CLI_CONFIG_FILE.
--
Here's what happens when I run terraform plan and set TF_CLI_CONFIG_FILE to:
- an absolute path to a file that exists
- an absolute path to a file that DOESN'T exist
- a path to a file that exists, which starts with
~/
In each of the 3 examples I've truncated the logs so they finish at this log : [INFO] backend/local: starting Plan operation. All logs related to the CLI config are still there.
Expected Behavior
I would expect Terraform to provide feedback to the user if it cannot use the path supplied via the TF_CLI_CONFIG_FILE environment variable - either due to it pointing at a non-existent file or unable to use for other reasons (e.g. starting with ~/).
For the 3 scenarios my debug outputs above show, I would expect:
- Already shows expected behaviour - a warning about dev_overrides is shown at the top of the terminal output. This confirms that
TF_CLI_CONFIG_FILEis doing what I expect. - I would expect a similar warning to show, except it tells me that a file cannot be found at the path supplied and that
TF_CLI_CONFIG_FILEis not impacting the CLI configuration. - Ideally would be able to use file paths starting with
~/and behave like (1). Alternatively, it could behave like my expectations for (2) by printing a warning.
Actual Behavior
- A warning about dev_overrides is shown at the top of the terminal output. This confirms that
TF_CLI_CONFIG_FILEis doing what I expect. - There is no warning about
TF_CLI_CONFIG_FILEnot contributing to CLI config, and the CLI proceeds without being configured - There is no warning about
TF_CLI_CONFIG_FILEnot contributing to CLI config, and the CLI proceeds without being configured
Steps to Reproduce
- Create a small TF configuration using a provider (e.g.
google) - Create a CLI configuration file that configures a developer override for that provider
- Run
terraform init, withoutTF_CLI_CONFIG_FILEset, to create lock file etc - Run
TF_CLI_CONFIG_FILE=<path> terraform planwhere the path value is an absolute path to the file made in step 2. You will see a warning about developer overrides in effect, and then the plan is displayed. - Run
TF_CLI_CONFIG_FILE=<path> terraform planwhere the path value is an absolute path to a file that doesn't exist. You will see no warnings about developer overrides, the command proceed with a provider downloaded from the Registry, and then the plan is displayed. - Run
TF_CLI_CONFIG_FILE=<path> terraform planwhere the path value is a path to the file made in step 2 that starts with "~/". You will see no warnings about developer overrides, the command proceed with a provider downloaded from the Registry, and then the plan is displayed.
Note: if (3) isn't done then steps (5) and (6) will instead have an inconsistent dependency lock file error.
Additional Context
No other ENVs are set that impact Terraform (e.g. TERRAFORM_CONFIG is not being used)
References
No response