Merge pull request #30905 from hashicorp/sebasslash/rename-env-vars

Rename cloud env vars to use `TF_CLOUD` prefix
This commit is contained in:
Sebastian Rivera 2022-04-20 16:35:37 -04:00 committed by GitHub
commit 2f7aa2fcb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 27 deletions

View File

@ -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))

View File

@ -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() != "" {

View File

@ -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",

View File

@ -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))
}

View File

@ -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