Skip to content

Commit c05fe8b

Browse files
feat: Cluster resource Tagg - Private Endpoint Service (#126)
Co-authored-by: TSowbaranika <[email protected]>
1 parent cf1d5c0 commit c05fe8b

File tree

11 files changed

+662
-0
lines changed

11 files changed

+662
-0
lines changed

API.md

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
import { CfnServerlessPrivateEndpoint, CfnServerlessPrivateEndpointProps,AwsPrivateEndpointConfig} from 'awscdk-resources-mongodbatlas';
4+
5+
interface AtlasStackProps {
6+
readonly projectId: string;
7+
readonly profile: string;
8+
readonly instanceName: string;
9+
readonly comment : string;
10+
readonly createAndAssignAwsPrivateEndpoint: boolean;
11+
}
12+
13+
export class CdkTestingStack extends cdk.Stack {
14+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
15+
super(scope, id, props);
16+
17+
const atlasProps = this.getContextProps();
18+
19+
const awsPrivateEndpointConfig : AwsPrivateEndpointConfig = {
20+
vpcId: "vpc-078fe50fc2313c001",
21+
subnetIds:["subnet-0a2f7a198e5d6d6a6"],
22+
region:""
23+
}
24+
const myServerlessInstance = new CfnServerlessPrivateEndpoint(this, 'ServerlessPrivateEndpointWithAws', {
25+
projectId: atlasProps.projectId,
26+
profile: atlasProps.profile,
27+
instanceName: atlasProps.instanceName,
28+
comment : atlasProps.comment,
29+
createAndAssignAwsPrivateEndpoint:atlasProps.createAndAssignAwsPrivateEndpoint,
30+
awsPrivateEndpointConfigurationProperties: awsPrivateEndpointConfig
31+
});
32+
}
33+
34+
getContextProps(): AtlasStackProps {
35+
const projectId = this.node.tryGetContext('projectId');
36+
if (!projectId){
37+
throw "No context value specified for orgId. Please specify via the cdk context."
38+
}
39+
40+
const profile = this.node.tryGetContext('profile') ?? 'default';
41+
const instanceName = this.node.tryGetContext('instanceName');
42+
const comment = this.node.tryGetContext('comment');
43+
const createAndAssignAwsPrivateEndpoint = this.node.tryGetContext('createAndAssignAwsPrivateEndpoint') ?? false;
44+
45+
46+
return {
47+
projectId,
48+
profile,
49+
instanceName,
50+
comment,
51+
createAndAssignAwsPrivateEndpoint
52+
}
53+
}
54+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export {
111111
CfnCluster,
112112
CfnClusterPropsEncryptionAtRestProvider,
113113
AdvancedRegionConfigProviderName,
114+
Tag,
114115
} from "./l1-resources/clusters";
115116

116117
export {

src/l1-resources/clusters/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ const clusterRes = new CfnCluster(this, 'ClusterResource', {
4949
clusterType: atlasProps.clusterType,
5050
backupEnabled: true,
5151
pitEnabled: false,
52+
tags: [
53+
{
54+
key: "env",
55+
value: "development",
56+
},
57+
],
5258
replicationSpecs: [{
5359
numShards: 1,
5460
advancedRegionConfigs: [{

src/l1-resources/clusters/index.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ export interface CfnClusterProps {
124124
* @schema CfnClusterProps#TerminationProtectionEnabled
125125
*/
126126
readonly terminationProtectionEnabled?: boolean;
127+
128+
/**
129+
* List of settings that configure your cluster regions. For Global Clusters, each object in the array represents a zone where your clusters nodes deploy. For non-Global replica sets and sharded clusters, this array has one object representing where your clusters nodes deploy.
130+
*
131+
* @schema CfnClusterProps#Tags
132+
*/
133+
readonly tags?: Tag[];
127134
}
128135

129136
/**
@@ -156,6 +163,7 @@ export function toJson_CfnClusterProps(
156163
RootCertType: obj.rootCertType,
157164
VersionReleaseSystem: obj.versionReleaseSystem,
158165
TerminationProtectionEnabled: obj.terminationProtectionEnabled,
166+
Tags: obj.tags?.map((y) => toJson_Tag(y)),
159167
};
160168
// filter undefined values
161169
return Object.entries(result).reduce(
@@ -526,6 +534,49 @@ export function toJson_AdvancedReplicationSpec(
526534
}
527535
/* eslint-enable max-len, quote-props */
528536

537+
/**
538+
* Advanced configuration details to add for one cluster in the specified project.
539+
*
540+
* @schema tag
541+
*/
542+
export interface Tag {
543+
/**
544+
* Constant that defines the set of the tag. For example, environment in the environment : production tag.
545+
*
546+
* @schema tag#Key
547+
*/
548+
readonly key?: string;
549+
550+
/**
551+
* Variable that belongs to the set of the tag. For example, production in the environment : production tag.
552+
*
553+
* @schema tag#Value
554+
*/
555+
readonly value?: string;
556+
}
557+
558+
/**
559+
* Converts an object of type 'Tag' to JSON representation.
560+
*/
561+
/* eslint-disable max-len, quote-props */
562+
export function toJson_Tag(
563+
obj: Tag | undefined
564+
): Record<string, any> | undefined {
565+
if (obj === undefined) {
566+
return undefined;
567+
}
568+
const result = {
569+
Key: obj.key,
570+
Value: obj.value,
571+
};
572+
// filter undefined values
573+
return Object.entries(result).reduce(
574+
(r, i) => (i[1] === undefined ? r : { ...r, [i[0]]: i[1] }),
575+
{}
576+
);
577+
}
578+
/* eslint-enable max-len, quote-props */
579+
529580
/**
530581
* Hardware specifications for nodes set for a given region. Each regionConfigs object describes the region's priority in elections and the number and type of MongoDB nodes that MongoDB Cloud deploys to the region. Each regionConfigs object must have either an analyticsSpecs object, electableSpecs object, or readOnlySpecs object. Tenant clusters only require electableSpecs. Dedicated clusters can specify any of these specifications, but must have at least one electableSpecs object within a replicationSpec. Every hardware specification must use the same instanceSize.
531582
*
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as cdk from "aws-cdk-lib";
2+
import { CfnCluster } from "./index";
3+
4+
const app = new cdk.App();
5+
const stack = new cdk.Stack(app, "atlas-test-cdk-test", {
6+
env: {
7+
region: process.env.CDK_DEFAULT_REGION,
8+
account: process.env.CDK_DEFAULT_ACCOUNT,
9+
},
10+
});
11+
12+
const atlasProject = "";
13+
14+
new CfnCluster(stack, "AtlasCluster", {
15+
projectId: atlasProject,
16+
name: "TestCluster",
17+
mongoDbMajorVersion: "6.0",
18+
clusterType: "REPLICASET",
19+
backupEnabled: true,
20+
tags: [
21+
{
22+
key: "env",
23+
value: "development",
24+
},
25+
],
26+
replicationSpecs: [
27+
{
28+
numShards: 1,
29+
advancedRegionConfigs: [
30+
{
31+
autoScaling: {
32+
diskGb: {
33+
enabled: true,
34+
},
35+
compute: {
36+
enabled: true,
37+
scaleDownEnabled: false,
38+
maxInstanceSize: "M40",
39+
},
40+
},
41+
electableSpecs: {
42+
ebsVolumeType: "PROVISIONED",
43+
instanceSize: "M30",
44+
nodeCount: 3,
45+
diskIops: "2000",
46+
},
47+
priority: 7,
48+
regionName: "EU_WEST_1",
49+
},
50+
],
51+
},
52+
],
53+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# serverless-private-endpoint
2+
3+
The official [MongoDB Atlas](https://www.mongodb.com/) AWS CDK resource for Node.js.
4+
5+
> AWS CDK [L1 construct] and data structures for the [AWS CloudFormation Registry] type `MongoDB::Atlas::ServerlessPrivateEndpoint` v1.0.0.
6+
7+
[l1 construct]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html
8+
[aws cloudformation registry]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html
9+
10+
## Description
11+
12+
Returns, adds, edits, and removes serverless instances.
13+
14+
## MongoDB Atlas API Docs
15+
16+
For more information about the API refer to: [API Endpoints](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/serverless-private-endpoints)
17+
18+
## Usage
19+
20+
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:
21+
22+
```sh
23+
aws cloudformation activate-type \
24+
--type-name MongoDB::Atlas::ServerlessPrivateEndpoint \
25+
--publisher-id bb989456c78c398a858fef18f2ca1bfc1fbba082 \
26+
--type RESOURCE \
27+
--execution-role-arn ROLE-ARN
28+
```
29+
30+
Alternatively:
31+
32+
```sh
33+
aws cloudformation activate-type \
34+
--public-type-arn arn:aws:cloudformation:us-east-1::type/resource/bb989456c78c398a858fef18f2ca1bfc1fbba082/MongoDB-Atlas-ServerlessPrivateEndpoint \
35+
--execution-role-arn ROLE-ARN
36+
```
37+
38+
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).
39+
40+
## Example: [serverless-private-endpoint.ts](../../../examples/l1-resources/serverless-private-endpoint.ts)
41+
42+
```ts
43+
import {
44+
CfnServerlessPrivateEndpoint,
45+
CfnServerlessPrivateEndpointProps
46+
} from 'awscdk-resources-mongodbatlas'
47+
48+
const myServerlessPrivateEndpoint = new CfnServerlessPrivateEndpoint(
49+
stack,
50+
'serverless-stack',
51+
{
52+
profile: 'default',
53+
instanceName: 'ServerlessPrivateEndpoint0',
54+
projectId: '',
55+
comment: 'this is a comment',
56+
createAndAssignAwsPrivateEndpoint: true,
57+
awsPrivateEndpointConfigurationProperties: {
58+
vpcId: 'vpc-',
59+
subnetIds: ['subnet-'],
60+
region: 'us-east-1'
61+
}
62+
}
63+
)
64+
```
65+
66+
## Feedback
67+
68+
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::ServerlessPrivateEndpoint`.
69+
70+
- 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-ServerlessPrivateEndpoint+v1.0.0).
71+
- Issues related to `MongoDB::Atlas::ServerlessPrivateEndpoint` should be reported to the [publisher](https://github.com/mongodb/mongodbatlas-cloudformation-resources/issues).
72+
- Feature requests should be [reported here](https://feedback.mongodb.com/forums/924145-atlas?category_id=392596)
73+
74+
[cdklabs/cdk-cloudformation]: https://github.com/cdklabs/cdk-cloudformation
75+
76+
## License
77+
78+
Distributed under the Apache-2.0 License.

0 commit comments

Comments
 (0)