Skip to content

Commit

Permalink
fix: adjust format of database user resource id as defined in previou…
Browse files Browse the repository at this point in the history
…s versions (#1506)
  • Loading branch information
AgustinBettati committed Oct 6, 2023
1 parent 1c91138 commit 586229f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 7 additions & 3 deletions mongodbatlas/fw_resource_mongodbatlas_database_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mongodbatlas
import (
"context"
"errors"
"fmt"
"net/http"
"regexp"

Expand Down Expand Up @@ -391,9 +390,14 @@ func newTFDatabaseUserModel(ctx context.Context, model *tfDatabaseUserModel, dbU
return nil, diagnostic
}

id := fmt.Sprintf("%s-%s-%s", dbUser.GroupID, dbUser.Username, dbUser.DatabaseName)
// ID is encoded to preserve format defined in previous versions.
encodedID := encodeStateID(map[string]string{
"project_id": dbUser.GroupID,
"username": dbUser.Username,
"auth_database_name": dbUser.DatabaseName,
})
databaseUserModel := &tfDatabaseUserModel{
ID: types.StringValue(id),
ID: types.StringValue(encodedID),
ProjectID: types.StringValue(dbUser.GroupID),
AuthDatabaseName: types.StringValue(dbUser.DatabaseName),
Username: types.StringValue(dbUser.Username),
Expand Down
7 changes: 2 additions & 5 deletions mongodbatlas/fw_resource_mongodbatlas_database_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,9 @@ func testAccCheckMongoDBAtlasDatabaseUserImportStateIDFunc(resourceName string)
return "", fmt.Errorf("not found: %s", resourceName)
}

projectID, username, authDatabaseName, err := splitDatabaseUserImportID(rs.Primary.ID)
if err != nil {
return "", fmt.Errorf("error splitting database User info from ID: %s", rs.Primary.ID)
}
ids := decodeStateID(rs.Primary.ID)

return fmt.Sprintf("%s-%s-%s", projectID, username, authDatabaseName), nil
return fmt.Sprintf("%s-%s-%s", ids["project_id"], ids["username"], ids["auth_database_name"]), nil
}
}

Expand Down

0 comments on commit 586229f

Please sign in to comment.