From 6ad894188d708393c90284d5121ba0d3e907acde Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 28 Jan 2025 12:06:23 +0000 Subject: [PATCH] Pass along to Terraform process --- bundle/deploy/terraform/init.go | 7 +++++++ bundle/deploy/terraform/init_test.go | 2 ++ 2 files changed, 9 insertions(+) diff --git a/bundle/deploy/terraform/init.go b/bundle/deploy/terraform/init.go index 5957611a4..a4e0f3bbb 100644 --- a/bundle/deploy/terraform/init.go +++ b/bundle/deploy/terraform/init.go @@ -105,6 +105,13 @@ var envCopy = []string{ // This is set in Azure DevOps by the AzureCLI@2 task. "AZURE_CONFIG_FILE", + // Include $AZURE_CONFIG_DIR in set of environment variables to pass along. + // This is set by Azure CLI as per https://learn.microsoft.com/en-us/cli/azure/azure-cli-configuration#cli-configuration-file + azureConfigDir, ok := env.Lookup(ctx, "AZURE_CONFIG_DIR") + if ok { + environ["AZURE_CONFIG_DIR"] = azureConfigDir + } + // Include $TF_CLI_CONFIG_FILE to override terraform provider in development. // See: https://developer.hashicorp.com/terraform/cli/config/config-file#explicit-installation-method-configuration "TF_CLI_CONFIG_FILE", diff --git a/bundle/deploy/terraform/init_test.go b/bundle/deploy/terraform/init_test.go index c7a4ffe4a..45dd3f7e6 100644 --- a/bundle/deploy/terraform/init_test.go +++ b/bundle/deploy/terraform/init_test.go @@ -293,6 +293,7 @@ func TestInheritEnvVars(t *testing.T) { t.Setenv("PATH", "/foo:/bar") t.Setenv("TF_CLI_CONFIG_FILE", "/tmp/config.tfrc") t.Setenv("AZURE_CONFIG_FILE", "/tmp/foo/bar") + t.Setenv("AZURE_CONFIG_DIR", "/tmp/foo") ctx := context.Background() env := map[string]string{} @@ -302,6 +303,7 @@ func TestInheritEnvVars(t *testing.T) { assert.Equal(t, "/foo:/bar", env["PATH"]) assert.Equal(t, "/tmp/config.tfrc", env["TF_CLI_CONFIG_FILE"]) assert.Equal(t, "/tmp/foo/bar", env["AZURE_CONFIG_FILE"]) + assert.Equal(t, "/tmp/foo", env["AZURE_CONFIG_DIR"]) } }