mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #30917 from hashicorp/sebasslash/config-token-precedence
Give the configuration token higher precedence over the CLI config file
This commit is contained in:
commit
c557078704
@ -44,6 +44,7 @@ BUG FIXES:
|
||||
* When rendering a diff, Terraform now quotes the name of any object attribute whose string representation is not a valid identifier. ([#30766](https://github.com/hashicorp/terraform/issues/30766))
|
||||
* Terraform will prioritize local terraform variables over remote terraform variables in operations such as `import`, `plan`, `refresh` and `apply` for workspaces in local execution mode. This behavior applies to both `remote` backend and the `cloud` integration configuration. ([#29972](https://github.com/hashicorp/terraform/issues/29972))
|
||||
* `terraform show -json`: JSON plan output now correctly maps aliased providers to their configurations, and includes the full provider source address alongside the short provider name. ([#30138](https://github.com/hashicorp/terraform/issues/30138))
|
||||
* The local token configuration now has higher priority than the token specified in a CLI configuration. ([#30664](https://github.com/hashicorp/terraform/issues/30664))
|
||||
|
||||
## Previous Releases
|
||||
|
||||
|
@ -256,9 +256,17 @@ func (b *Remote) Configure(obj cty.Value) tfdiags.Diagnostics {
|
||||
return diags
|
||||
}
|
||||
|
||||
// Get the token from the config.
|
||||
var token string
|
||||
if val := obj.GetAttr("token"); !val.IsNull() {
|
||||
token = val.AsString()
|
||||
}
|
||||
|
||||
// Retrieve the token for this host as configured in the credentials
|
||||
// section of the CLI Config File.
|
||||
token, err := b.token()
|
||||
// section of the CLI Config File if no token was configured for this
|
||||
// host in the config.
|
||||
if token == "" {
|
||||
token, err = b.token()
|
||||
if err != nil {
|
||||
diags = diags.Append(tfdiags.AttributeValue(
|
||||
tfdiags.Error,
|
||||
@ -268,13 +276,6 @@ func (b *Remote) Configure(obj cty.Value) tfdiags.Diagnostics {
|
||||
))
|
||||
return diags
|
||||
}
|
||||
|
||||
// Get the token from the config if no token was configured for this
|
||||
// host in credentials section of the CLI Config File.
|
||||
if token == "" {
|
||||
if val := obj.GetAttr("token"); !val.IsNull() {
|
||||
token = val.AsString()
|
||||
}
|
||||
}
|
||||
|
||||
// Return an error if we still don't have a token at this point.
|
||||
|
@ -214,9 +214,16 @@ func (b *Cloud) Configure(obj cty.Value) tfdiags.Diagnostics {
|
||||
return diags
|
||||
}
|
||||
|
||||
// Retrieve the token for this host as configured in the credentials
|
||||
// section of the CLI Config File.
|
||||
token, err := b.token()
|
||||
// First we'll retrieve the token from the configuration
|
||||
var token string
|
||||
if val := obj.GetAttr("token"); !val.IsNull() {
|
||||
token = val.AsString()
|
||||
}
|
||||
|
||||
// Get the token from the CLI Config File in the credentials section
|
||||
// if no token was not set in the configuration
|
||||
if token == "" {
|
||||
token, err = b.token()
|
||||
if err != nil {
|
||||
diags = diags.Append(tfdiags.AttributeValue(
|
||||
tfdiags.Error,
|
||||
@ -226,13 +233,6 @@ func (b *Cloud) Configure(obj cty.Value) tfdiags.Diagnostics {
|
||||
))
|
||||
return diags
|
||||
}
|
||||
|
||||
// Get the token from the config if no token was configured for this
|
||||
// host in credentials section of the CLI Config File.
|
||||
if token == "" {
|
||||
if val := obj.GetAttr("token"); !val.IsNull() {
|
||||
token = val.AsString()
|
||||
}
|
||||
}
|
||||
|
||||
// Return an error if we still don't have a token at this point.
|
||||
|
Loading…
Reference in New Issue
Block a user