Skip to content

Commit 54d4237

Browse files
authored
Improve error message for insufficient permissions (#427)
This patch produces a better error message when the user's token does not have correct permissions to create DBs.
1 parent 72212e2 commit 54d4237

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

internal/provider/resource_database.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ func waitForDatabaseAndUpdateResource(ctx context.Context, resourceData *schema.
512512
return retry.RetryableError(fmt.Errorf("error while fetching database: %s", string(res.Body)))
513513
}
514514

515+
// Status code == 401 Unauthorized
516+
if res.StatusCode() == http.StatusUnauthorized {
517+
return retry.NonRetryableError(fmt.Errorf("User not authorized. Effective role must have 'View DB' permission on the database (or on all DBs in the current org)"))
518+
}
515519
// Status code > 200 NOT retried
516520
if res.StatusCode() > http.StatusOK || res.JSON200 == nil {
517521
return retry.NonRetryableError(fmt.Errorf("unexpected response fetching database, status code: %d, message %s", res.StatusCode(), string(res.Body)))
@@ -605,8 +609,11 @@ func ensureValidRegions(ctx context.Context, client *astra.ClientWithResponses,
605609
regionsResp, err := client.ListServerlessRegionsWithResponse(ctx, params)
606610
if err != nil {
607611
return diag.FromErr(err)
612+
} else if regionsResp.StatusCode() == http.StatusUnauthorized {
613+
// if we get a 401 back, we don't have the "Create DB" permission
614+
return diag.Errorf("User not authorized. Effective role must have 'Create DB' permission to list available regions")
608615
} else if regionsResp.StatusCode() != http.StatusOK {
609-
return diag.Errorf("unexpected list available regions response: %s", string(regionsResp.Body))
616+
return diag.Errorf("unexpected response listing available regions: %s, return code: %d", string(regionsResp.Body), regionsResp.StatusCode())
610617
}
611618
// make sure all of the regions are valid
612619
cloudProvider := resourceData.Get("cloud_provider").(string)

0 commit comments

Comments
 (0)