Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTMDB-295: Fixes a bug about unauthorized error in project resource #664

Merged
merged 2 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion mongodbatlas/data_source_mongodbatlas_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mongodbatlas
import (
"context"
"errors"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -140,7 +141,11 @@ func dataSourceMongoDBAtlasProjectRead(ctx context.Context, d *schema.ResourceDa

apiKeys, err := getProjectAPIKeys(ctx, conn, project.OrgID, project.ID)
if err != nil {
return diag.Errorf("error getting project's api keys (%s): %s", projectID, err)
var target *matlas.ErrorResponse
if errors.As(err, &target) && target.ErrorCode != "USER_UNAUTHORIZED" {
return diag.Errorf("error getting project's api keys (%s): %s", projectID, err)
}
log.Println("[WARN] `api_keys` will be empty because the user has no permissions to read the api keys endpoint")
}

if err := d.Set("org_id", project.OrgID); err != nil {
Expand Down
8 changes: 7 additions & 1 deletion mongodbatlas/resource_mongodbatlas_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package mongodbatlas

import (
"context"
"errors"
"log"
"net/http"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -168,7 +170,11 @@ func resourceMongoDBAtlasProjectRead(ctx context.Context, d *schema.ResourceData

apiKeys, err := getProjectAPIKeys(ctx, conn, projectRes.OrgID, projectRes.ID)
if err != nil {
return diag.Errorf("error getting project's api keys (%s): %s", projectID, err)
var target *matlas.ErrorResponse
if errors.As(err, &target) && target.ErrorCode != "USER_UNAUTHORIZED" {
return diag.Errorf("error getting project's api keys (%s): %s", projectID, err)
}
log.Println("[WARN] `api_keys` will be empty because the user has no permissions to read the api keys endpoint")
}

if err := d.Set("name", projectRes.Name); err != nil {
Expand Down