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
24 changes: 13 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.

41 changes: 30 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 @@ -88,12 +88,14 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
}

apikeyInputs := setAPIkeyInputs(currentModel)
setDefaultsIfNotDefined(currentModel)

// 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 +123,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 +147,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 +169,13 @@ 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 {
setDefaultsIfNotDefined(currentModel)
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 +201,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 +305,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 All @@ -309,6 +314,7 @@ func (model *Model) getOrgDetails(ctx context.Context, conn *admin.APIClient, cu
model.ApiAccessListRequired = settings.ApiAccessListRequired
model.MultiFactorAuthRequired = settings.MultiFactorAuthRequired
model.RestrictEmployeeAccess = settings.RestrictEmployeeAccess
model.GenAIFeaturesEnabled = settings.GenAIFeaturesEnabled

return model, response, nil
}
Expand Down Expand Up @@ -352,5 +358,18 @@ func newOrganizationSettings(model *Model) *admin.OrganizationSettings {
ApiAccessListRequired: model.ApiAccessListRequired,
MultiFactorAuthRequired: model.MultiFactorAuthRequired,
RestrictEmployeeAccess: model.RestrictEmployeeAccess,
GenAIFeaturesEnabled: model.GenAIFeaturesEnabled,
}
}

func setDefaultsIfNotDefined(m *Model) {
if m == nil {
return
}
if m.SkipDefaultAlertsSettings == nil {
m.SkipDefaultAlertsSettings = util.Pointer(true)
}
if m.GenAIFeaturesEnabled == nil {
m.GenAIFeaturesEnabled = util.Pointer(true)
}
}
24 changes: 24 additions & 0 deletions cfn-resources/organization/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ 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="#genaifeaturesenabled" title="GenAIFeaturesEnabled">GenAIFeaturesEnabled</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 +39,8 @@ 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="#genaifeaturesenabled" title="GenAIFeaturesEnabled">GenAIFeaturesEnabled</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 +113,26 @@ _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)

#### GenAIFeaturesEnabled

Flag that indicates whether this organization has access to generative AI features. This setting only applies to Atlas Commercial and defaults to `true`. With this setting on, Project Owners may be able to enable or disable individual AI features at the project level. To learn more, see https://www.mongodb.com/docs/generative-ai-faq/

_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
10 changes: 10 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,16 @@
"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
},
"GenAIFeaturesEnabled": {
"type": "boolean",
"description": "Flag that indicates whether this organization has access to generative AI features. This setting only applies to Atlas Commercial and defaults to `true`. With this setting on, Project Owners may be able to enable or disable individual AI features at the project level. To learn more, see https://www.mongodb.com/docs/generative-ai-faq/",
"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
4 changes: 3 additions & 1 deletion cfn-resources/organization/test/inputs_1_create.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
},
"MultiFactorAuthRequired": "true",
"RestrictEmployeeAccess": "false",
"ApiAccessListRequired": "false"
"ApiAccessListRequired": "false",
"SkipDefaultAlertsSettings": "true",
"GenAIFeaturesEnabled": "true"
}
4 changes: 3 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,7 @@
},
"MultiFactorAuthRequired": "true",
"RestrictEmployeeAccess": "true",
"ApiAccessListRequired": "false"
"ApiAccessListRequired": "false",
"SkipDefaultAlertsSettings": "false",
"GenAIFeaturesEnabled": "false"
}
26 changes: 26 additions & 0 deletions examples/organization/organization.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@
"false"
],
"Default": "false"
},
"SkipDefaultAlertsSettings": {
"Type": "String",
"ConstraintDescription": "boolean",
"AllowedValues": [
"true",
"false"
],
"Default": "true",
"Description": "SkipDefaultAlertsSettings"
},
"GenAIFeaturesEnabled": {
"Type": "String",
"ConstraintDescription": "boolean",
"AllowedValues": [
"true",
"false"
],
"Default": "true",
"Description": "Flag that indicates whether this organization has access to generative AI features. This setting only applies to Atlas Commercial and defaults to `true`. With this setting on, Project Owners may be able to enable or disable individual AI features at the project level. To learn more, see https://www.mongodb.com/docs/generative-ai-faq/"
}
},
"Mappings": {},
Expand Down Expand Up @@ -113,6 +133,12 @@
},
"RestrictEmployeeAccess": {
"Ref": "RestrictEmployeeAccess"
},
"SkipDefaultAlertsSettings": {
"Ref": "SkipDefaultAlertsSettings"
},
"GenAIFeaturesEnabled": {
"Ref": "GenAIFeaturesEnabled"
}
}
}
Expand Down
Loading