Skip to content

Commit 72e690b

Browse files
authored
feat: Adds ResourcePolicy L1 construct, adds ProjectOwnerId parameter in project creationg and deprecates data-lake (#360)
1 parent f030ed8 commit 72e690b

File tree

11 files changed

+1377
-95
lines changed

11 files changed

+1377
-95
lines changed

API.md

Lines changed: 955 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
import { CfnResourcePolicy, CfnResourcePolicyProps } from 'awscdk-resources-mongodbatlas'
4+
import { env } from 'node:process';
5+
6+
interface AtlasStackProps {
7+
readonly profile: string;
8+
readonly name: string;
9+
readonly orgId: string;
10+
readonly body: string;
11+
}
12+
13+
const app = new cdk.App();
14+
15+
export class CdkTestStack extends cdk.Stack {
16+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
17+
super(scope, id, props);
18+
19+
const atlasProps = this.getContextProps();
20+
const resourcePolicy = new CfnResourcePolicy(this, "resource-policy-testing-stack", {
21+
profile: atlasProps.profile,
22+
name: atlasProps.name,
23+
orgId: atlasProps.orgId,
24+
policies: [
25+
{
26+
body: atlasProps.body,
27+
},
28+
],
29+
});
30+
}
31+
32+
getContextProps(): AtlasStackProps {
33+
const profile = this.node.tryGetContext('profile') ?? 'default';
34+
const name = this.node.tryGetContext('name');
35+
const orgId = this.node.tryGetContext('orgId');
36+
const body = this.node.tryGetContext('body');
37+
if (!name) {
38+
throw "No context value specified for name. Please specify via the cdk context."
39+
}
40+
if (!orgId) {
41+
throw "No context value specified for orgId. Please specify via the cdk context."
42+
}
43+
if (!body) {
44+
throw "No context value specified for body. Please specify via the cdk context."
45+
}
46+
47+
return {
48+
profile,
49+
name,
50+
orgId,
51+
body
52+
}
53+
}
54+
55+
}

src/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ L1 constructs are called Cfn (short for CloudFormation) resources. These resourc
3838
| project | Retrieves or creates projects in any given Atlas organization. | [README.md](l1-resources/project/README.md) |
3939
| project-invitation | Returns, send project invitations. | [README.md](l1-resources/project-invitation/README.md) |
4040
| project-ip-access-list | Returns, adds, edits, and removes network access limits to database deployments in MongoDB Cloud. | [README.md](l1-resources/project-ip-access-list/README.md) |
41+
| resource-policy | Returns, adds, edits, and removes Atlas Resource Policies. | [README.md](l1-resources/resource-policy/README.md) |
4142
| search-deployment | The resource lets you create, edit and delete dedicated search nodes in a cluster. | [README.md](l1-resources/search-deployment/README.md) |
4243
| search-index | Returns, adds, edits, and removes Atlas Search indexes. Also returns and updates user-defined analyzers. | [README.md](l1-resources/search-index/README.md) |
4344
| serverless-instance | Returns, adds, edits, and removes serverless instances. | [README.md](l1-resources/serverless-instance/README.md) |

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ export {
308308
ListOptions,
309309
} from "./l1-resources/project-ip-access-list";
310310

311+
export {
312+
CfnResourcePolicy,
313+
CfnResourcePolicyProps,
314+
ApiAtlasPolicy,
315+
ApiAtlasUserMetadata,
316+
} from "./l1-resources/resource-policy";
317+
311318
export {
312319
CfnSearchDeployment,
313320
CfnSearchDeploymentProps,

src/l1-resources/data-lake-pipeline/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as cdk from "aws-cdk-lib";
33
import * as constructs from "constructs";
44

55
/**
6-
* An example resource schema demonstrating some basic constructs and validation rules.
6+
* Data Lake is deprecated. As of September 2024, Data Lake is deprecated. If you use Data Lake, you should migrate to alternative solutions before the service is removed. To learn more, see <https://dochub.mongodb.org/core/data-lake-deprecation>. This resource returns, adds, edits, and removes data lake pipelines.
77
*
88
* @schema CfnDataLakePipelineProps
99
*/

src/l1-resources/project/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export interface CfnProjectProps {
2222
*/
2323
readonly orgId: string;
2424

25+
/**
26+
* Unique identifier of the organization within which to create the project.
27+
*
28+
* @schema CfnProjectProps#ProjectOwnerId
29+
*/
30+
readonly projectOwnerId?: string;
31+
2532
/**
2633
* Flag that indicates whether to create the project with default alert settings.
2734
*
@@ -81,6 +88,7 @@ export function toJson_CfnProjectProps(
8188
const result = {
8289
Name: obj.name,
8390
OrgId: obj.orgId,
91+
ProjectOwnerId: obj.projectOwnerId,
8492
WithDefaultAlertsSettings: obj.withDefaultAlertsSettings,
8593
ProjectSettings: toJson_ProjectSettings(obj.projectSettings),
8694
Profile: obj.profile,
@@ -278,10 +286,6 @@ export class CfnProject extends cdk.CfnResource {
278286
* Attribute `MongoDB::Atlas::Project.Created`
279287
*/
280288
public readonly attrCreated: string;
281-
/**
282-
* Attribute `MongoDB::Atlas::Project.ProjectOwnerId`
283-
*/
284-
public readonly attrProjectOwnerId: string;
285289
/**
286290
* Attribute `MongoDB::Atlas::Project.ClusterCount`
287291
*/
@@ -304,7 +308,6 @@ export class CfnProject extends cdk.CfnResource {
304308

305309
this.attrId = cdk.Token.asString(this.getAtt("Id"));
306310
this.attrCreated = cdk.Token.asString(this.getAtt("Created"));
307-
this.attrProjectOwnerId = cdk.Token.asString(this.getAtt("ProjectOwnerId"));
308311
this.attrClusterCount = cdk.Token.asNumber(this.getAtt("ClusterCount"));
309312
}
310313
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# resource-policy
2+
3+
The official [MongoDB Atlas](https://www.mongodb.com/) AWS CDK resource for Node.js.
4+
5+
> **NOTE**:
6+
> - **Atlas Resource Policies functionality is currently in Preview, you'll need to enable `Atlas Resource Policies` Beta Feature in your organization to use it.**
7+
8+
> AWS CDK [L1 construct] and data structures for the [AWS CloudFormation Registry] type `MongoDB::Atlas::ResourcePolicy`.
9+
[L1 construct]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html
10+
[AWS CloudFormation Registry]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html
11+
12+
## Description
13+
14+
Returns, adds, edits, and removes Atlas resource policies.
15+
16+
## MongoDB Atlas API Docs
17+
18+
For more information about the API refer to: [API Endpoints](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Atlas-Resource-Policies)
19+
20+
## Usage
21+
22+
> [Using Atlas Resource Policy with Cloudformation](https://github.com/mongodb/mongodbatlas-cloudformation-resources/blob/master/examples/resource-policy/resource-policy.json)
23+
24+
In order to use this library, you will need to activate this AWS CloudFormation Registry type in your account. You can do this via the AWS Management Console or using the [AWS CLI](https://aws.amazon.com/cli/) using the following command:
25+
26+
```sh
27+
aws cloudformation activate-type \
28+
--type-name MongoDB::Atlas::ResourcePolicy \
29+
--publisher-id bb989456c78c398a858fef18f2ca1bfc1fbba082 \
30+
--type RESOURCE \
31+
--execution-role-arn ROLE-ARN
32+
```
33+
34+
Alternatively:
35+
36+
```sh
37+
aws cloudformation activate-type \
38+
--public-type-arn arn:aws:cloudformation:us-east-1::type/resource/bb989456c78c398a858fef18f2ca1bfc1fbba082/MongoDB-Atlas-ResourcePolicy \
39+
--execution-role-arn ROLE-ARN
40+
```
41+
42+
You can find more information about activating this type in the [AWS CloudFormation documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry-public.html).
43+
44+
## Example: [resource-policy.ts](../../../examples/l1-resources/resource-policy.ts)
45+
```ts
46+
import { CfnResourcePolicy } from 'awscdk-resources-mongodbatlas';
47+
48+
const resourcePolicy = new CfnResourcePolicy(this, "resource-policy-testing-stack", {
49+
profile: atlasProps.profile,
50+
name: atlasProps.name,
51+
orgId: atlasProps.orgId,
52+
policies: [
53+
{
54+
body: atlasProps.body,
55+
},
56+
],
57+
});
58+
```
59+
60+
## Feedback
61+
62+
This library is auto-generated and published to all supported programming languages by the [cdklabs/cdk-cloudformation] project based on the API schema published for `MongoDB::Atlas::ResourcePolicy`.
63+
64+
* Issues related to this generated library should be [reported here](https://github.com/cdklabs/cdk-cloudformation/issues/new?title=Issue+with+%40cdk-cloudformation%2Fmongodb-atlas-resource-policy+v1.0.0).
65+
* Issues related to `MongoDB::Atlas::ResourcePolicy` should be reported to the [publisher](https://github.com/mongodb/mongodbatlas-cloudformation-resources/issues).
66+
* Feature requests should be [reported here](https://feedback.mongodb.com/forums/924145-atlas?category_id=392596)
67+
68+
[cdklabs/cdk-cloudformation]: https://github.com/cdklabs/cdk-cloudformation
69+
70+
## License
71+
72+
Distributed under the Apache-2.0 License.

0 commit comments

Comments
 (0)