Always use token in backend config when provided

This commit is contained in:
Keith Clawson 2022-03-11 18:00:22 -08:00 committed by Sebastian Rivera
parent 39bbcf2f9c
commit 23dffee568

View File

@ -256,9 +256,17 @@ func (b *Remote) Configure(obj cty.Value) tfdiags.Diagnostics {
return diags 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 // Retrieve the token for this host as configured in the credentials
// section of the CLI Config File. // section of the CLI Config File if no token was configured for this
token, err := b.token() // host in the config.
if token == "" {
token, err = b.token()
if err != nil { if err != nil {
diags = diags.Append(tfdiags.AttributeValue( diags = diags.Append(tfdiags.AttributeValue(
tfdiags.Error, tfdiags.Error,
@ -268,13 +276,6 @@ func (b *Remote) Configure(obj cty.Value) tfdiags.Diagnostics {
)) ))
return diags 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. // Return an error if we still don't have a token at this point.