Merge pull request #28684 from hashicorp/radditude/org-read-error

backend/remote: clearer error when we fail to read the organization
This commit is contained in:
CJ Horton 2021-05-12 14:15:08 -07:00 committed by GitHub
commit dc71cd4495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -321,15 +321,16 @@ func (b *Remote) Configure(obj cty.Value) tfdiags.Diagnostics {
entitlements, err := b.client.Organizations.Entitlements(context.Background(), b.organization) entitlements, err := b.client.Organizations.Entitlements(context.Background(), b.organization)
if err != nil { if err != nil {
if err == tfe.ErrResourceNotFound { if err == tfe.ErrResourceNotFound {
err = fmt.Errorf("organization %s does not exist", b.organization) err = fmt.Errorf("organization %q at host %s not found.\n\n"+
"Please ensure that the organization and hostname are correct "+
"and that your API token for %s is valid.",
b.organization, b.hostname, b.hostname)
} }
diags = diags.Append(tfdiags.AttributeValue( diags = diags.Append(tfdiags.AttributeValue(
tfdiags.Error, tfdiags.Error,
"Failed to read organization entitlements", fmt.Sprintf("Failed to read organization %q at host %s", b.organization, b.hostname),
fmt.Sprintf( fmt.Sprintf("The \"remote\" backend encountered an unexpected error while reading the "+
`The "remote" backend encountered an unexpected error while reading the `+ "organization settings: %s", err),
`organization settings: %s.`, err,
),
cty.Path{cty.GetAttrStep{Name: "organization"}}, cty.Path{cty.GetAttrStep{Name: "organization"}},
)) ))
return diags return diags

View File

@ -55,7 +55,7 @@ func TestRemote_config(t *testing.T) {
"prefix": cty.NullVal(cty.String), "prefix": cty.NullVal(cty.String),
}), }),
}), }),
confErr: "organization nonexisting does not exist", confErr: "organization \"nonexisting\" at host app.terraform.io not found",
}, },
"with_an_unknown_host": { "with_an_unknown_host": {
config: cty.ObjectVal(map[string]cty.Value{ config: cty.ObjectVal(map[string]cty.Value{