From f63ef2b5ef0b44fe677d02f598d6610b7c880385 Mon Sep 17 00:00:00 2001 From: Sebastian Rivera Date: Wed, 20 Apr 2022 13:36:23 -0400 Subject: [PATCH] Rename cloud env vars to use TF_CLOUD prefix --- CHANGELOG.md | 4 ++-- internal/cloud/backend.go | 12 ++++++------ internal/cloud/backend_test.go | 24 ++++++++++++------------ internal/cloud/e2e/env_variables_test.go | 8 ++++---- website/docs/cli/cloud/settings.mdx | 6 +++--- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be60642f76..c33c7825c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,8 +25,8 @@ ENHANCEMENTS: * Error messages for preconditions, postconditions, and custom variable validations are now evaluated as expressions, allowing interpolation of relevant values into the output. ([#30613](https://github.com/hashicorp/terraform/issues/30613)) * There are some small improvements to the error and warning messages Terraform will emit in the case of invalid provider configuration passing between modules. There are no changes to which situations will produce errors and warnings, but the messages now include additional information intended to clarify what problem Terraform is describing and how to address it. ([#30639](https://github.com/hashicorp/terraform/issues/30639)) * When running `terraform plan`, only show external changes which may have contributed to the current plan ([#30486](https://github.com/hashicorp/terraform/issues/30486)) -* Add `TF_ORGANIZATION` environment variable fallback for `organization` in the cloud configuration -* Add `TF_HOSTNAME` environment variable fallback for `hostname` in the cloud configuration +* Add `TF_CLOUD_ORGANIZATION` environment variable fallback for `organization` in the cloud configuration +* Add `TF_CLOUD_HOSTNAME` environment variable fallback for `hostname` in the cloud configuration * `TF_WORKSPACE` can now be used to configure the `workspaces` attribute in your cloud configuration * When running on macOS, Terraform will now use platform APIs to validate certificates presented by TLS (HTTPS) servers. This may change exactly which root certificates Terraform will accept as valid. ([#30768](https://github.com/hashicorp/terraform/issues/30768)) * The AzureRM Backend now defaults to using MSAL (and Microsoft Graph) rather than ADAL (and Azure Active Directory Graph) for authentication. ([#30891](https://github.com/hashicorp/terraform/issues/30891)) diff --git a/internal/cloud/backend.go b/internal/cloud/backend.go index cdb59cf2d8..9a01af33f0 100644 --- a/internal/cloud/backend.go +++ b/internal/cloud/backend.go @@ -155,9 +155,9 @@ func (b *Cloud) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics) { // check if organization is specified in the config. if val := obj.GetAttr("organization"); val.IsNull() || val.AsString() == "" { // organization is specified in the config but is invalid, so - // we'll fallback on TF_ORGANIZATION - if val := os.Getenv("TF_ORGANIZATION"); val == "" { - diags = diags.Append(missingConfigAttributeAndEnvVar("organization", "TF_ORGANIZATION")) + // we'll fallback on TF_CLOUD_ORGANIZATION + if val := os.Getenv("TF_CLOUD_ORGANIZATION"); val == "" { + diags = diags.Append(missingConfigAttributeAndEnvVar("organization", "TF_CLOUD_ORGANIZATION")) } } @@ -355,7 +355,7 @@ func (b *Cloud) setConfigurationFields(obj cty.Value) tfdiags.Diagnostics { var diags tfdiags.Diagnostics // Get the hostname. - b.hostname = os.Getenv("TF_HOSTNAME") + b.hostname = os.Getenv("TF_CLOUD_HOSTNAME") if val := obj.GetAttr("hostname"); !val.IsNull() && val.AsString() != "" { b.hostname = val.AsString() } else if b.hostname == "" { @@ -363,10 +363,10 @@ func (b *Cloud) setConfigurationFields(obj cty.Value) tfdiags.Diagnostics { } // We can have two options, setting the organization via the config - // or using TF_ORGANIZATION. Since PrepareConfig() validates that one of these + // or using TF_CLOUD_ORGANIZATION. Since PrepareConfig() validates that one of these // values must exist, we'll initially set it to the env var and override it if // specified in the configuration. - b.organization = os.Getenv("TF_ORGANIZATION") + b.organization = os.Getenv("TF_CLOUD_ORGANIZATION") // Check if the organization is present and valid in the config. if val := obj.GetAttr("organization"); !val.IsNull() && val.AsString() != "" { diff --git a/internal/cloud/backend_test.go b/internal/cloud/backend_test.go index f857c5cef5..33afc124d0 100644 --- a/internal/cloud/backend_test.go +++ b/internal/cloud/backend_test.go @@ -86,7 +86,7 @@ func TestCloud_PrepareConfig(t *testing.T) { "tags": cty.NullVal(cty.Set(cty.String)), }), }), - expectedErr: `Invalid or missing required argument: "organization" must be set in the cloud configuration or as an environment variable: TF_ORGANIZATION.`, + expectedErr: `Invalid or missing required argument: "organization" must be set in the cloud configuration or as an environment variable: TF_CLOUD_ORGANIZATION.`, }, "null workspace": { config: cty.ObjectVal(map[string]cty.Value{ @@ -161,7 +161,7 @@ func TestCloud_PrepareConfigWithEnvVars(t *testing.T) { }), }), vars: map[string]string{ - "TF_ORGANIZATION": "example-org", + "TF_CLOUD_ORGANIZATION": "example-org", }, }, "with no organization attribute or env var": { @@ -173,7 +173,7 @@ func TestCloud_PrepareConfigWithEnvVars(t *testing.T) { }), }), vars: map[string]string{}, - expectedErr: `Invalid or missing required argument: "organization" must be set in the cloud configuration or as an environment variable: TF_ORGANIZATION.`, + expectedErr: `Invalid or missing required argument: "organization" must be set in the cloud configuration or as an environment variable: TF_CLOUD_ORGANIZATION.`, }, "null workspace": { config: cty.ObjectVal(map[string]cty.Value{ @@ -190,8 +190,8 @@ func TestCloud_PrepareConfigWithEnvVars(t *testing.T) { "workspaces": cty.NullVal(cty.String), }), vars: map[string]string{ - "TF_ORGANIZATION": "hashicorp", - "TF_WORKSPACE": "my-workspace", + "TF_CLOUD_ORGANIZATION": "hashicorp", + "TF_WORKSPACE": "my-workspace", }, }, } @@ -242,7 +242,7 @@ func TestCloud_configWithEnvVars(t *testing.T) { }), }), vars: map[string]string{ - "TF_ORGANIZATION": "hashicorp", + "TF_CLOUD_ORGANIZATION": "hashicorp", }, expectedOrganization: "hashicorp", }, @@ -257,7 +257,7 @@ func TestCloud_configWithEnvVars(t *testing.T) { }), }), vars: map[string]string{ - "TF_ORGANIZATION": "we-should-not-see-this", + "TF_CLOUD_ORGANIZATION": "we-should-not-see-this", }, expectedOrganization: "hashicorp", }, @@ -272,7 +272,7 @@ func TestCloud_configWithEnvVars(t *testing.T) { }), }), vars: map[string]string{ - "TF_HOSTNAME": "private.hashicorp.engineering", + "TF_CLOUD_HOSTNAME": "private.hashicorp.engineering", }, expectedHostname: "private.hashicorp.engineering", }, @@ -287,7 +287,7 @@ func TestCloud_configWithEnvVars(t *testing.T) { }), }), vars: map[string]string{ - "TF_HOSTNAME": "mycool.tfe-host.io", + "TF_CLOUD_HOSTNAME": "mycool.tfe-host.io", }, expectedHostname: "private.hashicorp.engineering", }, @@ -386,9 +386,9 @@ func TestCloud_configWithEnvVars(t *testing.T) { "workspaces": cty.NullVal(cty.String), }), vars: map[string]string{ - "TF_ORGANIZATION": "mordor", - "TF_WORKSPACE": "mt-doom", - "TF_HOSTNAME": "mycool.tfe-host.io", + "TF_CLOUD_ORGANIZATION": "mordor", + "TF_WORKSPACE": "mt-doom", + "TF_CLOUD_HOSTNAME": "mycool.tfe-host.io", }, expectedOrganization: "mordor", expectedWorkspaceName: "mt-doom", diff --git a/internal/cloud/e2e/env_variables_test.go b/internal/cloud/e2e/env_variables_test.go index 3cf0096440..1044432bfd 100644 --- a/internal/cloud/e2e/env_variables_test.go +++ b/internal/cloud/e2e/env_variables_test.go @@ -17,7 +17,7 @@ func Test_cloud_organization_env_var(t *testing.T) { t.Cleanup(cleanup) cases := testCases{ - "with TF_ORGANIZATION set": { + "with TF_CLOUD_ORGANIZATION set": { operations: []operationSets{ { prep: func(t *testing.T, orgName, dir string) { @@ -50,7 +50,7 @@ func Test_cloud_organization_env_var(t *testing.T) { }, } - testRunner(t, cases, 0, fmt.Sprintf("TF_ORGANIZATION=%s", org.Name)) + testRunner(t, cases, 0, fmt.Sprintf("TF_CLOUD_ORGANIZATION=%s", org.Name)) } func Test_cloud_workspace_name_env_var(t *testing.T) { @@ -258,7 +258,7 @@ func Test_cloud_null_config(t *testing.T) { } testRunner(t, cases, 1, - fmt.Sprintf(`TF_ORGANIZATION=%s`, org.Name), - fmt.Sprintf(`TF_HOSTNAME=%s`, tfeHostname), + fmt.Sprintf(`TF_CLOUD_ORGANIZATION=%s`, org.Name), + fmt.Sprintf(`TF_CLOUD_HOSTNAME=%s`, tfeHostname), fmt.Sprintf(`TF_WORKSPACE=%s`, wk.Name)) } diff --git a/website/docs/cli/cloud/settings.mdx b/website/docs/cli/cloud/settings.mdx index ad40e15798..cdb1a4147b 100644 --- a/website/docs/cli/cloud/settings.mdx +++ b/website/docs/cli/cloud/settings.mdx @@ -89,12 +89,12 @@ You can use environment variables to configure one or more `cloud` block attribu Use the following environment variables to configure the `cloud` block: -- `TF_ORGANIZATION` - The name of the organization. Serves as a fallback for `organization` +- `TF_CLOUD_ORGANIZATION` - The name of the organization. Serves as a fallback for `organization` in the cloud configuration. If both are specified, the configuration takes precedence. -- `TF_HOSTNAME` - The hostname of a Terraform Enterprise installation. Serves as a fallback if `hostname` is not specified in the cloud configuration. If both are specified, the configuration takes precendence. +- `TF_CLOUD_HOSTNAME` - The hostname of a Terraform Enterprise installation. Serves as a fallback if `hostname` is not specified in the cloud configuration. If both are specified, the configuration takes precendence. -- `TF_WORKSPACE` - The name of a single Terraform Cloud workspace. If the `workspaces` attribute is not included in your configuration file, the `cloud` block interprets `TF_WORKSPACE` as the `name` value of the `workspaces` attribute. The workspace must exist in the organization specified in the configuration or `TF_ORGANIZATION`. If the `cloud` block uses tags, Terraform Cloud will return an error if the value of `TF_WORKSPACE` is not included in the set of tags. Refer to [TF_WORKSPACE](https://www.terraform.io/cli/config/environment-variables#tf_workspace) for more details. +- `TF_WORKSPACE` - The name of a single Terraform Cloud workspace. If the `workspaces` attribute is not included in your configuration file, the `cloud` block interprets `TF_WORKSPACE` as the `name` value of the `workspaces` attribute. The workspace must exist in the organization specified in the configuration or `TF_CLOUD_ORGANIZATION`. If the `cloud` block uses tags, Terraform Cloud will return an error if the value of `TF_WORKSPACE` is not included in the set of tags. Refer to [TF_WORKSPACE](https://www.terraform.io/cli/config/environment-variables#tf_workspace) for more details. ## Excluding Files from Upload with .terraformignore