Skip to content
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
1 change: 1 addition & 0 deletions cfn-resources/database-user/cmd/resource/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions cfn-resources/database-user/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
"go.mongodb.org/atlas-sdk/v20231115014/admin"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
)

var CreateRequiredFields = []string{constants.DatabaseName, constants.ProjectID, constants.Roles, constants.Username}
Expand Down Expand Up @@ -68,7 +68,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler

groupID := *currentModel.ProjectId

_, resp, err := client.Atlas20231115014.DatabaseUsersApi.CreateDatabaseUser(context.Background(), groupID, dbUser).Execute()
_, resp, err := client.AtlasSDK.DatabaseUsersApi.CreateDatabaseUser(context.Background(), groupID, dbUser).Execute()
if err != nil {
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
}
Expand Down Expand Up @@ -99,13 +99,14 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
groupID := *currentModel.ProjectId
username := *currentModel.Username
dbName := *currentModel.DatabaseName
databaseUser, resp, err := client.Atlas20231115014.DatabaseUsersApi.GetDatabaseUser(context.Background(), groupID, dbName, username).Execute()
databaseUser, resp, err := client.AtlasSDK.DatabaseUsersApi.GetDatabaseUser(context.Background(), groupID, dbName, username).Execute()
if err != nil {
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
}

_, _ = logger.Debugf("databaseUser:%+v", databaseUser)
currentModel.DatabaseName = &databaseUser.DatabaseName
currentModel.Description = databaseUser.Description
currentModel.LdapAuthType = databaseUser.LdapAuthType
currentModel.AWSIAMType = databaseUser.AwsIAMType
currentModel.X509Type = databaseUser.X509Type
Expand Down Expand Up @@ -176,7 +177,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler

groupID := *currentModel.ProjectId

_, resp, err := client.Atlas20231115014.DatabaseUsersApi.UpdateDatabaseUser(context.Background(), groupID, *currentModel.DatabaseName, *currentModel.Username, dbUser).Execute()
_, resp, err := client.AtlasSDK.DatabaseUsersApi.UpdateDatabaseUser(context.Background(), groupID, *currentModel.DatabaseName, *currentModel.Username, dbUser).Execute()
if err != nil {
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
}
Expand Down Expand Up @@ -208,7 +209,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
groupID := *currentModel.ProjectId
databaseName := *currentModel.DatabaseName
username := *currentModel.Username
_, resp, err := client.Atlas20231115014.DatabaseUsersApi.DeleteDatabaseUser(context.Background(), groupID, databaseName, username).Execute()
resp, err := client.AtlasSDK.DatabaseUsersApi.DeleteDatabaseUser(context.Background(), groupID, databaseName, username).Execute()
if err != nil {
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
}
Expand Down Expand Up @@ -239,7 +240,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P

dbUserModels := make([]interface{}, 0)

databaseUsers, resp, err := client.Atlas20231115014.DatabaseUsersApi.ListDatabaseUsers(context.Background(), groupID).Execute()
databaseUsers, resp, err := client.AtlasSDK.DatabaseUsersApi.ListDatabaseUsers(context.Background(), groupID).Execute()
if err != nil {
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
}
Expand All @@ -249,6 +250,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
databaseUser := dbUserResults[i]
var model = Model{
DatabaseName: &databaseUser.DatabaseName,
Description: databaseUser.Description,
LdapAuthType: databaseUser.LdapAuthType,
X509Type: databaseUser.X509Type,
Username: &databaseUser.Username,
Expand Down Expand Up @@ -363,6 +365,7 @@ func setModel(currentModel *Model) (*admin.CloudDatabaseUser, error) {
AwsIAMType: currentModel.AWSIAMType,
X509Type: currentModel.X509Type,
DeleteAfterDate: util.StringPtrToTimePtr(currentModel.DeleteAfterDate),
Description: currentModel.Description,
}

if util.IsStringPresent(currentModel.Password) {
Expand Down
12 changes: 12 additions & 0 deletions cfn-resources/database-user/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ To declare this entity in your AWS CloudFormation template, use the following sy
"<a href="#deleteafterdate" title="DeleteAfterDate">DeleteAfterDate</a>" : <i>String</i>,
"<a href="#awsiamtype" title="AWSIAMType">AWSIAMType</a>" : <i>String</i>,
"<a href="#databasename" title="DatabaseName">DatabaseName</a>" : <i>String</i>,
"<a href="#description" title="Description">Description</a>" : <i>String</i>,
"<a href="#labels" title="Labels">Labels</a>" : <i>[ <a href="labeldefinition.md">labelDefinition</a>, ... ]</i>,
"<a href="#ldapauthtype" title="LdapAuthType">LdapAuthType</a>" : <i>String</i>,
"<a href="#x509type" title="X509Type">X509Type</a>" : <i>String</i>,
Expand All @@ -36,6 +37,7 @@ Properties:
<a href="#deleteafterdate" title="DeleteAfterDate">DeleteAfterDate</a>: <i>String</i>
<a href="#awsiamtype" title="AWSIAMType">AWSIAMType</a>: <i>String</i>
<a href="#databasename" title="DatabaseName">DatabaseName</a>: <i>String</i>
<a href="#description" title="Description">Description</a>: <i>String</i>
<a href="#labels" title="Labels">Labels</a>: <i>
- <a href="labeldefinition.md">labelDefinition</a></i>
<a href="#ldapauthtype" title="LdapAuthType">LdapAuthType</a>: <i>String</i>
Expand Down Expand Up @@ -84,6 +86,16 @@ _Type_: String

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### Description

Description of this database user.

_Required_: No

_Type_: String

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### Labels

List that contains the key-value pairs for tagging and categorizing the MongoDB database user. The labels that you define do not appear in the console.
Expand Down
4 changes: 4 additions & 0 deletions cfn-resources/database-user/mongodb-atlas-databaseuser.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
"description": "MongoDB database against which the MongoDB database user authenticates. MongoDB database users must provide both a username and authentication database to log into MongoDB. Default value is `admin`.",
"type": "string"
},
"Description": {
"description": "Description of this database user.",
"type": "string"
},
"Labels": {
"description": "List that contains the key-value pairs for tagging and categorizing the MongoDB database user. The labels that you define do not appear in the console.",
"items": {
Expand Down
5 changes: 3 additions & 2 deletions cfn-resources/database-user/test/cfn-test-create-inputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rm -rf inputs
mkdir inputs

projectName="${1}"
MONGODB_ATLAS_PROFILE=${MONGODB_ATLAS_PROFILE:-"default"}
projectId=$(atlas projects list --output json | jq --arg NAME "${projectName}" -r '.results[] | select(.name==$NAME) | .id')
if [ -z "$projectId" ]; then
projectId=$(atlas projects create "${projectName}" --output=json | jq -r '.id')
Expand All @@ -32,8 +33,8 @@ echo "Check if a project is created $projectId"
cd "$(dirname "$0")" || exit
for inputFile in inputs_*; do
outputFile=${inputFile//$WORDTOREMOVE/}
jq --arg ProjectId "$projectId" \
'.ProjectId?|=$ProjectId' \
jq --arg ProjectId "$projectId" --arg Profile "${MONGODB_ATLAS_PROFILE}" \
'.ProjectId?|=$ProjectId | .Profile?|=$Profile' \
"$inputFile" >"../inputs/$outputFile"
done
cd ..
Expand Down
39 changes: 20 additions & 19 deletions cfn-resources/database-user/test/inputs_1_create.template.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"Username" : "DataUser1",
"Password" : "MongoDB12345%",
"ProjectId" : "ProjectId",
"Profile" : "default",
"DatabaseName": "admin",
"Roles": [
{ "RoleName": "readWrite",
"DatabaseName": "testdb",
"CollectionName": "col1"
}
],
"Scopes": [
{ "Type": "CLUSTER",
"Name": "testdb"
}
]


}
"Username": "DataUser1",
"Password": "MongoDB12345%",
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
"Profile": "${MONGODB_ATLAS_PROFILE}",
"DatabaseName": "admin",
"Description": "Desc 1",
"Roles": [
{
"RoleName": "readWrite",
"DatabaseName": "testdb",
"CollectionName": "col1"
}
],
"Scopes": [
{
"Type": "CLUSTER",
"Name": "testdb"
}
]
}
44 changes: 24 additions & 20 deletions cfn-resources/database-user/test/inputs_1_update.template.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
{
"Username" : "DataUser1",
"Password" : "MongoDB12345%",
"ProjectId" : "ProjectId",
"Profile" : "default",
"Username": "DataUser1",
"Password": "MongoDB12345%",
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
"Description": "Desc 2",
"Profile": "${MONGODB_ATLAS_PROFILE}",
"DatabaseName": "admin",
"Roles": [
{ "RoleName": "readWrite",
"DatabaseName": "testdb",
"CollectionName": "col1"
},
{ "RoleName": "read",
"DatabaseName": "proddb",
"CollectionName": "col1"
}
],
"Scopes": [
{ "Type": "CLUSTER",
"Name": "testdb"
}
]
}
"Roles": [
{
"RoleName": "readWrite",
"DatabaseName": "testdb",
"CollectionName": "col1"
},
{
"RoleName": "read",
"DatabaseName": "proddb",
"CollectionName": "col1"
}
],
"Scopes": [
{
"Type": "CLUSTER",
"Name": "testdb"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"Username": "arn:aws:iam::111111967292:role/cfn-admin",
"AWSIAMType": "ROLE",
"ProjectId": "ProjectId",
"Profile": "default",
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
Copy link
Collaborator

@oarbusi oarbusi Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change if then it's not used in cfn-resources/database-user/test/cfn-test-create-inputs.sh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to support new contract-test and release workflow (see https://jira.mongodb.org/browse/CLOUDP-282804 )

"Profile": "${MONGODB_ATLAS_PROFILE}",
"DatabaseName": "$external",
"Description": "Desc 1",
"Roles": [
{
"RoleName": "readWrite",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Username": "arn:aws:iam::111111967292:role/cfn-admin",
"AWSIAMType": "ROLE",
"ProjectId": "ProjectId",
"Profile": "default",
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}",
"Profile": "${MONGODB_ATLAS_PROFILE}",
"DatabaseName": "$external",
"Roles": [
{
Expand Down
7 changes: 7 additions & 0 deletions examples/database-user/scramUser.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"Type": "String",
"NoEcho": "true",
"Description": "Alphanumeric string that authenticates this database user against the database specified in databaseName. To authenticate with SCRAM-SHA, you must specify this parameter"
},
"Description": {
"Type": "String",
"Description": "Description of this database user."
}
},
"Mappings": {},
Expand All @@ -49,6 +53,9 @@
"DatabaseName": {
"Ref": "DatabaseName"
},
"Description": {
"Ref": "Description"
},
"Roles": [
{
"RoleName": "atlasAdmin",
Expand Down
Loading