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-205 fixing client update side effects #456

Merged
merged 1 commit into from
May 12, 2021
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
18 changes: 5 additions & 13 deletions mongodbatlas/resource_mongodbatlas_database_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"net/url"
"regexp"
"strings"

Expand Down Expand Up @@ -146,9 +145,8 @@ func resourceMongoDBAtlasDatabaseUserRead(d *schema.ResourceData, meta interface
authDatabaseName = d.Get("auth_database_name").(string)
}
}
usernameEscaped := url.PathEscape(username)

dbUser, _, err := conn.DatabaseUsers.Get(context.Background(), authDatabaseName, projectID, usernameEscaped)
dbUser, _, err := conn.DatabaseUsers.Get(context.Background(), authDatabaseName, projectID, username)
if err != nil {
// case 404
// deleted in the backend case
Expand Down Expand Up @@ -262,9 +260,7 @@ func resourceMongoDBAtlasDatabaseUserUpdate(d *schema.ResourceData, meta interfa
username := ids["username"]
authDatabaseName := ids["auth_database_name"]

usernameEscaped := url.PathEscape(username)

dbUser, _, err := conn.DatabaseUsers.Get(context.Background(), authDatabaseName, projectID, usernameEscaped)
dbUser, _, err := conn.DatabaseUsers.Get(context.Background(), authDatabaseName, projectID, username)
if err != nil {
return fmt.Errorf("error getting database user information to update it: %s", err)
}
Expand All @@ -285,7 +281,7 @@ func resourceMongoDBAtlasDatabaseUserUpdate(d *schema.ResourceData, meta interfa
dbUser.Scopes = expandScopes(d)
}

_, _, err = conn.DatabaseUsers.Update(context.Background(), projectID, usernameEscaped, dbUser)
_, _, err = conn.DatabaseUsers.Update(context.Background(), projectID, username, dbUser)
if err != nil {
return fmt.Errorf("error updating database user(%s): %s", username, err)
}
Expand All @@ -301,9 +297,7 @@ func resourceMongoDBAtlasDatabaseUserDelete(d *schema.ResourceData, meta interfa
username := ids["username"]
authDatabaseName := ids["auth_database_name"]

usernameEscaped := url.PathEscape(username)

_, err := conn.DatabaseUsers.Delete(context.Background(), authDatabaseName, projectID, usernameEscaped)
_, err := conn.DatabaseUsers.Delete(context.Background(), authDatabaseName, projectID, username)
if err != nil {
return fmt.Errorf("error deleting database user (%s): %s", username, err)
}
Expand All @@ -319,9 +313,7 @@ func resourceMongoDBAtlasDatabaseUserImportState(d *schema.ResourceData, meta in
return nil, err
}

usernameEscaped := url.PathEscape(*username)

u, _, err := conn.DatabaseUsers.Get(context.Background(), *authDatabaseName, *projectID, usernameEscaped)
u, _, err := conn.DatabaseUsers.Get(context.Background(), *authDatabaseName, *projectID, *username)
if err != nil {
return nil, fmt.Errorf("couldn't import user(%s) in project(%s), error: %s", *username, *projectID, err)
}
Expand Down
5 changes: 1 addition & 4 deletions mongodbatlas/resource_mongodbatlas_database_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"log"
"net/url"
"os"
"testing"

Expand Down Expand Up @@ -619,9 +618,7 @@ func testAccCheckMongoDBAtlasDatabaseUserExists(resourceName string, dbUser *mat
ids := decodeStateID(rs.Primary.ID)
username := ids["username"]

dbUsername := url.PathEscape(username)

if dbUserResp, _, err := conn.DatabaseUsers.Get(context.Background(), ids["auth_database_name"], ids["project_id"], dbUsername); err == nil {
if dbUserResp, _, err := conn.DatabaseUsers.Get(context.Background(), ids["auth_database_name"], ids["project_id"], username); err == nil {
*dbUser = *dbUserResp
return nil
}
Expand Down