Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 12 additions & 11 deletions cfn-resources/organization/cmd/resource/model.go

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

24 changes: 13 additions & 11 deletions cfn-resources/organization/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"net/http"
"time"

"go.mongodb.org/atlas-sdk/v20231115014/admin"
"go.mongodb.org/atlas-sdk/v20241113004/admin"
Copy link
Member

Choose a reason for hiding this comment

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

is it useful/possible to create some tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think anything else required at this point. I've updated contract tests to use the new params.


"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
"github.com/aws/aws-sdk-go/service/cloudformation"
Expand Down Expand Up @@ -76,7 +76,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
if peErr != nil {
return *peErr, nil
}
conn := client.Atlas20231115014
conn := client.AtlasSDK
ctx := context.Background()

_, _, err := secrets.Get(&req, *currentModel.AwsSecretName)
Expand All @@ -91,9 +91,10 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler

// Set the roles from model
orgInput := &admin.CreateOrganizationRequest{
ApiKey: apikeyInputs,
OrgOwnerId: currentModel.OrgOwnerId,
Name: *currentModel.Name,
ApiKey: apikeyInputs,
OrgOwnerId: currentModel.OrgOwnerId,
Name: *currentModel.Name,
SkipDefaultAlertsSettings: currentModel.SkipDefaultAlertsSettings,
}
if currentModel.FederatedSettingsId != nil {
orgInput.FederationSettingsId = currentModel.FederatedSettingsId
Expand Down Expand Up @@ -121,7 +122,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
if peErr != nil {
return *peErr, nil
}
conn = newOrgClient.Atlas20231115014
conn = newOrgClient.AtlasSDK
if _, _, errUpdate := conn.OrganizationsApi.UpdateOrganizationSettings(ctx, orgID, newOrganizationSettings(currentModel)).Execute(); errUpdate != nil {
return handleError(response, constants.CREATE, err)
}
Expand All @@ -145,7 +146,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
return *peErr, nil
}

model, response, err := currentModel.getOrgDetails(context.Background(), newOrgClient.Atlas20231115014, currentModel)
model, response, err := currentModel.getOrgDetails(context.Background(), newOrgClient.AtlasSDK, currentModel)
if err != nil {
return handleError(response, constants.READ, err)
}
Expand All @@ -167,11 +168,11 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
if peErr != nil {
return *peErr, nil
}
conn := newOrgClient.Atlas20231115014
conn := newOrgClient.AtlasSDK
ctx := context.Background()

atlasOrg := admin.AtlasOrganization{Id: currentModel.OrgId, Name: *currentModel.Name}
if _, response, err := conn.OrganizationsApi.RenameOrganization(ctx, *currentModel.OrgId, &atlasOrg).Execute(); err != nil {
atlasOrg := admin.AtlasOrganization{Id: currentModel.OrgId, Name: *currentModel.Name, SkipDefaultAlertsSettings: currentModel.SkipDefaultAlertsSettings}
if _, response, err := conn.OrganizationsApi.UpdateOrganization(ctx, *currentModel.OrgId, &atlasOrg).Execute(); err != nil {
return handleError(response, constants.UPDATE, err)
}

Expand All @@ -197,7 +198,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
if peErr != nil {
return *peErr, nil
}
conn := newOrgClient.Atlas20231115014
conn := newOrgClient.AtlasSDK
ctx := context.Background()

// Callback
Expand Down Expand Up @@ -301,6 +302,7 @@ func (model *Model) getOrgDetails(ctx context.Context, conn *admin.APIClient, cu
model.Name = util.Pointer(org.Name)
model.OrgId = org.Id
model.IsDeleted = org.IsDeleted
model.SkipDefaultAlertsSettings = org.SkipDefaultAlertsSettings

settings, _, err := conn.OrganizationsApi.GetOrganizationSettings(ctx, org.GetId()).Execute()
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions cfn-resources/organization/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ To declare this entity in your AWS CloudFormation template, use the following sy
"<a href="#orgownerid" title="OrgOwnerId">OrgOwnerId</a>" : <i>String</i>,
"<a href="#profile" title="Profile">Profile</a>" : <i>String</i>,
"<a href="#awssecretname" title="AwsSecretName">AwsSecretName</a>" : <i>String</i>,
"<a href="#skipdefaultalertssettings" title="SkipDefaultAlertsSettings">SkipDefaultAlertsSettings</a>" : <i>Boolean</i>,
"<a href="#isdeleted" title="IsDeleted">IsDeleted</a>" : <i>Boolean</i>,
"<a href="#apiaccesslistrequired" title="ApiAccessListRequired">ApiAccessListRequired</a>" : <i>Boolean</i>,
"<a href="#multifactorauthrequired" title="MultiFactorAuthRequired">MultiFactorAuthRequired</a>" : <i>Boolean</i>,
Expand All @@ -37,6 +38,7 @@ Properties:
<a href="#orgownerid" title="OrgOwnerId">OrgOwnerId</a>: <i>String</i>
<a href="#profile" title="Profile">Profile</a>: <i>String</i>
<a href="#awssecretname" title="AwsSecretName">AwsSecretName</a>: <i>String</i>
<a href="#skipdefaultalertssettings" title="SkipDefaultAlertsSettings">SkipDefaultAlertsSettings</a>: <i>Boolean</i>
<a href="#isdeleted" title="IsDeleted">IsDeleted</a>: <i>Boolean</i>
<a href="#apiaccesslistrequired" title="ApiAccessListRequired">ApiAccessListRequired</a>: <i>Boolean</i>
<a href="#multifactorauthrequired" title="MultiFactorAuthRequired">MultiFactorAuthRequired</a>: <i>Boolean</i>
Expand Down Expand Up @@ -109,6 +111,16 @@ _Type_: String

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

#### SkipDefaultAlertsSettings

Disables automatic alert creation. When set to `true`, Atlas doesn't automatically create organization-level alerts. Defaults to `true` for new Atlas Organizations created with the provider to prevent infrastructure drift caused by creation of new alerts.

_Required_: No

_Type_: Boolean

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

#### IsDeleted

Flag that indicates whether this organization has been deleted.
Expand Down
5 changes: 5 additions & 0 deletions cfn-resources/organization/mongodb-atlas-organization.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
"description": "AwsSecretName used to set newly created Org credentials information.",
"default": "default"
},
"SkipDefaultAlertsSettings": {
"type": "boolean",
"description": "Disables automatic alert creation. When set to `true`, Atlas doesn't automatically create organization-level alerts. Defaults to `true` for new Atlas Organizations created with the provider to prevent infrastructure drift caused by creation of new alerts.",
"default": "true"
},
"OrgId": {
"type": "string",
"description": "Unique 24-hexadecimal digit string that identifies the organization that contains your projects. Use the /orgs endpoint to retrieve all organizations to which the authenticated user has access.",
Expand Down
3 changes: 2 additions & 1 deletion cfn-resources/organization/test/inputs_1_update.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
},
"MultiFactorAuthRequired": "true",
"RestrictEmployeeAccess": "true",
"ApiAccessListRequired": "false"
"ApiAccessListRequired": "false",
"SkipDefaultAlertsSettings": "false"
}
Loading