mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Improve remote backend missing token error
Prompt the user to run terraform login to generate and store a token for the configured remote backend.
This commit is contained in:
parent
e57685d8fc
commit
f15e58adf8
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
tfe "github.com/hashicorp/go-tfe"
|
tfe "github.com/hashicorp/go-tfe"
|
||||||
version "github.com/hashicorp/go-version"
|
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-svchost/disco"
|
||||||
"github.com/hashicorp/terraform/backend"
|
"github.com/hashicorp/terraform/backend"
|
||||||
"github.com/hashicorp/terraform/configs/configschema"
|
"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.
|
// Return an error if we still don't have a token at this point.
|
||||||
if token == "" {
|
if token == "" {
|
||||||
|
loginCommand := "terraform login"
|
||||||
|
if b.hostname != defaultHostname {
|
||||||
|
loginCommand = loginCommand + " " + b.hostname
|
||||||
|
}
|
||||||
diags = diags.Append(tfdiags.Sourceless(
|
diags = diags.Append(tfdiags.Sourceless(
|
||||||
tfdiags.Error,
|
tfdiags.Error,
|
||||||
"Required token could not be found",
|
"Required token could not be found",
|
||||||
fmt.Sprintf(
|
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,
|
b.hostname,
|
||||||
|
loginCommand,
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
return diags
|
return diags
|
||||||
|
@ -64,6 +64,19 @@ func TestRemote_config(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
confErr: "Failed to request discovery document",
|
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": {
|
"with_a_name": {
|
||||||
config: cty.ObjectVal(map[string]cty.Value{
|
config: cty.ObjectVal(map[string]cty.Value{
|
||||||
"hostname": cty.NullVal(cty.String),
|
"hostname": cty.NullVal(cty.String),
|
||||||
|
Loading…
Reference in New Issue
Block a user