Skip to content

Commit f63ef2b

Browse files
committed
Rename cloud env vars to use TF_CLOUD prefix
1 parent d3e660d commit f63ef2b

5 files changed

Lines changed: 27 additions & 27 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ ENHANCEMENTS:
2525
* 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))
2626
* 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))
2727
* When running `terraform plan`, only show external changes which may have contributed to the current plan ([#30486](https://github.com/hashicorp/terraform/issues/30486))
28-
* Add `TF_ORGANIZATION` environment variable fallback for `organization` in the cloud configuration
29-
* Add `TF_HOSTNAME` environment variable fallback for `hostname` in the cloud configuration
28+
* Add `TF_CLOUD_ORGANIZATION` environment variable fallback for `organization` in the cloud configuration
29+
* Add `TF_CLOUD_HOSTNAME` environment variable fallback for `hostname` in the cloud configuration
3030
* `TF_WORKSPACE` can now be used to configure the `workspaces` attribute in your cloud configuration
3131
* 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))
3232
* 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))

‎internal/cloud/backend.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ func (b *Cloud) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics) {
155155
// check if organization is specified in the config.
156156
if val := obj.GetAttr("organization"); val.IsNull() || val.AsString() == "" {
157157
// organization is specified in the config but is invalid, so
158-
// we'll fallback on TF_ORGANIZATION
159-
if val := os.Getenv("TF_ORGANIZATION"); val == "" {
160-
diags = diags.Append(missingConfigAttributeAndEnvVar("organization", "TF_ORGANIZATION"))
158+
// we'll fallback on TF_CLOUD_ORGANIZATION
159+
if val := os.Getenv("TF_CLOUD_ORGANIZATION"); val == "" {
160+
diags = diags.Append(missingConfigAttributeAndEnvVar("organization", "TF_CLOUD_ORGANIZATION"))
161161
}
162162
}
163163

@@ -355,18 +355,18 @@ func (b *Cloud) setConfigurationFields(obj cty.Value) tfdiags.Diagnostics {
355355
var diags tfdiags.Diagnostics
356356

357357
// Get the hostname.
358-
b.hostname = os.Getenv("TF_HOSTNAME")
358+
b.hostname = os.Getenv("TF_CLOUD_HOSTNAME")
359359
if val := obj.GetAttr("hostname"); !val.IsNull() && val.AsString() != "" {
360360
b.hostname = val.AsString()
361361
} else if b.hostname == "" {
362362
b.hostname = defaultHostname
363363
}
364364

365365
// We can have two options, setting the organization via the config
366-
// or using TF_ORGANIZATION. Since PrepareConfig() validates that one of these
366+
// or using TF_CLOUD_ORGANIZATION. Since PrepareConfig() validates that one of these
367367
// values must exist, we'll initially set it to the env var and override it if
368368
// specified in the configuration.
369-
b.organization = os.Getenv("TF_ORGANIZATION")
369+
b.organization = os.Getenv("TF_CLOUD_ORGANIZATION")
370370

371371
// Check if the organization is present and valid in the config.
372372
if val := obj.GetAttr("organization"); !val.IsNull() && val.AsString() != "" {

‎internal/cloud/backend_test.go‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestCloud_PrepareConfig(t *testing.T) {
8686
"tags": cty.NullVal(cty.Set(cty.String)),
8787
}),
8888
}),
89-
expectedErr: `Invalid or missing required argument: "organization" must be set in the cloud configuration or as an environment variable: TF_ORGANIZATION.`,
89+
expectedErr: `Invalid or missing required argument: "organization" must be set in the cloud configuration or as an environment variable: TF_CLOUD_ORGANIZATION.`,
9090
},
9191
"null workspace": {
9292
config: cty.ObjectVal(map[string]cty.Value{
@@ -161,7 +161,7 @@ func TestCloud_PrepareConfigWithEnvVars(t *testing.T) {
161161
}),
162162
}),
163163
vars: map[string]string{
164-
"TF_ORGANIZATION": "example-org",
164+
"TF_CLOUD_ORGANIZATION": "example-org",
165165
},
166166
},
167167
"with no organization attribute or env var": {
@@ -173,7 +173,7 @@ func TestCloud_PrepareConfigWithEnvVars(t *testing.T) {
173173
}),
174174
}),
175175
vars: map[string]string{},
176-
expectedErr: `Invalid or missing required argument: "organization" must be set in the cloud configuration or as an environment variable: TF_ORGANIZATION.`,
176+
expectedErr: `Invalid or missing required argument: "organization" must be set in the cloud configuration or as an environment variable: TF_CLOUD_ORGANIZATION.`,
177177
},
178178
"null workspace": {
179179
config: cty.ObjectVal(map[string]cty.Value{
@@ -190,8 +190,8 @@ func TestCloud_PrepareConfigWithEnvVars(t *testing.T) {
190190
"workspaces": cty.NullVal(cty.String),
191191
}),
192192
vars: map[string]string{
193-
"TF_ORGANIZATION": "hashicorp",
194-
"TF_WORKSPACE": "my-workspace",
193+
"TF_CLOUD_ORGANIZATION": "hashicorp",
194+
"TF_WORKSPACE": "my-workspace",
195195
},
196196
},
197197
}
@@ -242,7 +242,7 @@ func TestCloud_configWithEnvVars(t *testing.T) {
242242
}),
243243
}),
244244
vars: map[string]string{
245-
"TF_ORGANIZATION": "hashicorp",
245+
"TF_CLOUD_ORGANIZATION": "hashicorp",
246246
},
247247
expectedOrganization: "hashicorp",
248248
},
@@ -257,7 +257,7 @@ func TestCloud_configWithEnvVars(t *testing.T) {
257257
}),
258258
}),
259259
vars: map[string]string{
260-
"TF_ORGANIZATION": "we-should-not-see-this",
260+
"TF_CLOUD_ORGANIZATION": "we-should-not-see-this",
261261
},
262262
expectedOrganization: "hashicorp",
263263
},
@@ -272,7 +272,7 @@ func TestCloud_configWithEnvVars(t *testing.T) {
272272
}),
273273
}),
274274
vars: map[string]string{
275-
"TF_HOSTNAME": "private.hashicorp.engineering",
275+
"TF_CLOUD_HOSTNAME": "private.hashicorp.engineering",
276276
},
277277
expectedHostname: "private.hashicorp.engineering",
278278
},
@@ -287,7 +287,7 @@ func TestCloud_configWithEnvVars(t *testing.T) {
287287
}),
288288
}),
289289
vars: map[string]string{
290-
"TF_HOSTNAME": "mycool.tfe-host.io",
290+
"TF_CLOUD_HOSTNAME": "mycool.tfe-host.io",
291291
},
292292
expectedHostname: "private.hashicorp.engineering",
293293
},
@@ -386,9 +386,9 @@ func TestCloud_configWithEnvVars(t *testing.T) {
386386
"workspaces": cty.NullVal(cty.String),
387387
}),
388388
vars: map[string]string{
389-
"TF_ORGANIZATION": "mordor",
390-
"TF_WORKSPACE": "mt-doom",
391-
"TF_HOSTNAME": "mycool.tfe-host.io",
389+
"TF_CLOUD_ORGANIZATION": "mordor",
390+
"TF_WORKSPACE": "mt-doom",
391+
"TF_CLOUD_HOSTNAME": "mycool.tfe-host.io",
392392
},
393393
expectedOrganization: "mordor",
394394
expectedWorkspaceName: "mt-doom",

‎internal/cloud/e2e/env_variables_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func Test_cloud_organization_env_var(t *testing.T) {
1717
t.Cleanup(cleanup)
1818

1919
cases := testCases{
20-
"with TF_ORGANIZATION set": {
20+
"with TF_CLOUD_ORGANIZATION set": {
2121
operations: []operationSets{
2222
{
2323
prep: func(t *testing.T, orgName, dir string) {
@@ -50,7 +50,7 @@ func Test_cloud_organization_env_var(t *testing.T) {
5050
},
5151
}
5252

53-
testRunner(t, cases, 0, fmt.Sprintf("TF_ORGANIZATION=%s", org.Name))
53+
testRunner(t, cases, 0, fmt.Sprintf("TF_CLOUD_ORGANIZATION=%s", org.Name))
5454
}
5555

5656
func Test_cloud_workspace_name_env_var(t *testing.T) {
@@ -258,7 +258,7 @@ func Test_cloud_null_config(t *testing.T) {
258258
}
259259

260260
testRunner(t, cases, 1,
261-
fmt.Sprintf(`TF_ORGANIZATION=%s`, org.Name),
262-
fmt.Sprintf(`TF_HOSTNAME=%s`, tfeHostname),
261+
fmt.Sprintf(`TF_CLOUD_ORGANIZATION=%s`, org.Name),
262+
fmt.Sprintf(`TF_CLOUD_HOSTNAME=%s`, tfeHostname),
263263
fmt.Sprintf(`TF_WORKSPACE=%s`, wk.Name))
264264
}

‎website/docs/cli/cloud/settings.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ You can use environment variables to configure one or more `cloud` block attribu
8989
Use the following environment variables to configure the `cloud` block:
9090

9191

92-
- `TF_ORGANIZATION` - The name of the organization. Serves as a fallback for `organization`
92+
- `TF_CLOUD_ORGANIZATION` - The name of the organization. Serves as a fallback for `organization`
9393
in the cloud configuration. If both are specified, the configuration takes precedence.
9494

95-
- `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.
95+
- `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.
9696

97-
- `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.
97+
- `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.
9898

9999
## Excluding Files from Upload with .terraformignore
100100

0 commit comments

Comments
 (0)