Merge pull request #24038 from hashicorp/alisdair/improve-remote-backend-missing-token-error
Improve remote backend missing token error
This commit is contained in:
commit
dd192e107b
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
tfe "github.com/hashicorp/go-tfe"
|
||||
version "github.com/hashicorp/go-version"
|
||||
"github.com/hashicorp/terraform-svchost"
|
||||
svchost "github.com/hashicorp/terraform-svchost"
|
||||
"github.com/hashicorp/terraform-svchost/disco"
|
||||
"github.com/hashicorp/terraform/backend"
|
||||
"github.com/hashicorp/terraform/configs/configschema"
|
||||
|
@ -267,12 +267,17 @@ func (b *Remote) Configure(obj cty.Value) tfdiags.Diagnostics {
|
|||
|
||||
// Return an error if we still don't have a token at this point.
|
||||
if token == "" {
|
||||
loginCommand := "terraform login"
|
||||
if b.hostname != defaultHostname {
|
||||
loginCommand = loginCommand + " " + b.hostname
|
||||
}
|
||||
diags = diags.Append(tfdiags.Sourceless(
|
||||
tfdiags.Error,
|
||||
"Required token could not be found",
|
||||
fmt.Sprintf(
|
||||
"Make sure you configured a credentials block for %s in your CLI Config File.",
|
||||
"Run the following command to generate a token for %s:\n %s",
|
||||
b.hostname,
|
||||
loginCommand,
|
||||
),
|
||||
))
|
||||
return diags
|
||||
|
|
|
@ -64,6 +64,19 @@ func TestRemote_config(t *testing.T) {
|
|||
}),
|
||||
confErr: "Failed to request discovery document",
|
||||
},
|
||||
// localhost advertises TFE services, but has no token in the credentials
|
||||
"without_a_token": {
|
||||
config: cty.ObjectVal(map[string]cty.Value{
|
||||
"hostname": cty.StringVal("localhost"),
|
||||
"organization": cty.StringVal("hashicorp"),
|
||||
"token": cty.NullVal(cty.String),
|
||||
"workspaces": cty.ObjectVal(map[string]cty.Value{
|
||||
"name": cty.StringVal("prod"),
|
||||
"prefix": cty.NullVal(cty.String),
|
||||
}),
|
||||
}),
|
||||
confErr: "terraform login localhost",
|
||||
},
|
||||
"with_a_name": {
|
||||
config: cty.ObjectVal(map[string]cty.Value{
|
||||
"hostname": cty.NullVal(cty.String),
|
||||
|
|
Loading…
Reference in New Issue