Skip to content

Commit 54daa3c

Browse files
authored
feat!: intmdb 1023 private endpoint service (#133)
1 parent 523e4d1 commit 54daa3c

File tree

19 files changed

+4701
-2484
lines changed

19 files changed

+4701
-2484
lines changed

API.md

Lines changed: 3842 additions & 2321 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
import { CfnPrivateEndpoint } from 'awscdk-resources-mongodbatlas';
4+
5+
interface AtlasStackProps {
6+
readonly projId: string;
7+
readonly profile: string;
8+
readonly region: string;
9+
readonly vpcId: string;
10+
readonly subnetId: string;
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+
new CfnPrivateEndpoint (this, "privateEndpoint", {
20+
projectId: atlasProps.projId,
21+
profile: atlasProps.profile,
22+
region: atlasProps.region,
23+
privateEndpoints: [
24+
{
25+
vpcId: atlasProps.vpcId,
26+
subnetIds: [atlasProps.subnetId]
27+
}
28+
],
29+
});
30+
}
31+
32+
getContextProps(): AtlasStackProps {
33+
const projId = this.node.tryGetContext('projId');
34+
if (!projId){
35+
throw "No context value specified for orgId. Please specify via the cdk context."
36+
}
37+
38+
const profile = this.node.tryGetContext('profile') ?? 'default';
39+
const region = this.node.tryGetContext('region');
40+
const vpcId = this.node.tryGetContext('vpcId');
41+
const subnetId = this.node.tryGetContext('comment');
42+
43+
44+
return {
45+
projId,
46+
profile,
47+
region,
48+
vpcId,
49+
subnetId,
50+
}
51+
}
52+
}

examples/l1-resources/private-endpoint.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { CfnPrivateEndpointAws } from './../../src/l1-resources/private-endpoint-aws/index';
12
import * as cdk from 'aws-cdk-lib';
3+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
24
import { Construct } from 'constructs';
3-
import { CfnPrivateEndpoint } from 'awscdk-resources-mongodbatlas';
5+
import { CfnPrivateEndpointService, CfnPrivateEndpointServicePropsCloudProvider } from '../../src/l1-resources/private-endpoint-service';
46

57
interface AtlasStackProps {
68
readonly projId: string;
@@ -10,23 +12,36 @@ interface AtlasStackProps {
1012
readonly subnetId: string;
1113
}
1214

13-
export class CdkTestingStack extends cdk.Stack {
15+
export class CdkPrivateEndpoint extends cdk.Stack {
1416
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
1517
super(scope, id, props);
1618

1719
const atlasProps = this.getContextProps();
1820

19-
const myPrivateEndpoint = new CfnPrivateEndpoint (this, "privateEndpoint", {
21+
const atlasService = new CfnPrivateEndpointService(this, "AtlasPrivateEndpointService", {
2022
projectId: atlasProps.projId,
21-
profile: atlasProps.profile,
23+
profile: atlasProps.profile,
2224
region: atlasProps.region,
23-
privateEndpoints: [
24-
{
25-
vpcId: atlasProps.vpcId,
26-
subnetIds: [atlasProps.subnetId]
27-
}
28-
],
25+
cloudProvider: CfnPrivateEndpointServicePropsCloudProvider.AWS
2926
});
27+
28+
const awsPrivateEndpoint = new ec2.CfnVPCEndpoint(this, 'AWSPrivateEndpoint', {
29+
serviceName: atlasService.attrEndpointServiceName,
30+
subnetIds: [atlasProps.subnetId],
31+
vpcEndpointType: 'Interface',
32+
vpcId: atlasProps.vpcId,
33+
});
34+
35+
awsPrivateEndpoint.addDependency(atlasService)
36+
37+
const myPrivateEndpoint = new CfnPrivateEndpointAws (this, "AtlasPrivateEndpoint", {
38+
projectId: atlasProps.projId,
39+
profile: atlasProps.profile,
40+
endpointServiceId: atlasService.attrId,
41+
id : awsPrivateEndpoint.ref,
42+
});
43+
44+
myPrivateEndpoint.addDependency(myPrivateEndpoint)
3045
}
3146

3247
getContextProps(): AtlasStackProps {

examples/l3-resources/atlas-basic-private-endpoint.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class CdkTestingStack extends cdk.Stack {
1818
super(scope, id, props);
1919

2020
const atlasProps = this.getContextProps();
21-
const atlasBasicPrivateEndpointasBasic = new AtlasBasicPrivateEndpoint(this, 'AtlasBasic', {
21+
new AtlasBasicPrivateEndpoint(this, 'AtlasBasic', {
2222
atlasBasicProps: {
2323
clusterProps: {
2424
name: atlasProps.clusterName,
@@ -53,13 +53,8 @@ export class CdkTestingStack extends cdk.Stack {
5353
}
5454
},
5555
privateEndpointProps: {
56-
privateEndpoints: [
57-
{
58-
vpcId: atlasProps.vpcId,
59-
subnetIds: [atlasProps.subnetId],
60-
}
61-
62-
]
56+
awsVpcId: atlasProps.vpcId,
57+
awsSubnetId: atlasProps.subnetId,
6358
},
6459
profile: atlasProps.profile,
6560

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,17 @@ export {
217217
PrivateEndpoint,
218218
} from "./l1-resources/private-endpoint";
219219

220+
export {
221+
CfnPrivateEndpointAwsProps,
222+
CfnPrivateEndpointAws,
223+
} from "./l1-resources/private-endpoint-aws";
224+
225+
export {
226+
CfnPrivateEndpointService,
227+
CfnPrivateEndpointServiceProps,
228+
CfnPrivateEndpointServicePropsCloudProvider,
229+
} from "./l1-resources/private-endpoint-service";
230+
220231
export {
221232
CfnServerlessPrivateEndpointProps,
222233
CfnServerlessPrivateEndpoint,
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# 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::PrivateEndpointAWS` 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+
Creates one private endpoint for the specified cloud service provider. This cloud service provider manages the private endpoint service, which in turn manages the private endpoints for the project. To use this resource, the requesting API Key must have the Project Owner role. To learn more about considerations, limitations, and prerequisites, see the MongoDB documentation for setting up a private endpoint.
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/Private-Endpoint-Services)
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::PrivateEndpointAWS \
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-PrivateEndpointAWS \
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: [private-endpoint.ts](../../../examples/l1-resources/private-endpoint.ts)
41+
42+
```ts
43+
import { CfnPrivateEndpoint } from 'awscdk-resources-mongodbatlas'
44+
45+
const myPrivateEndpoint = new CfnPrivateEndpointAws(this, 'privateEndpoint', {
46+
projectId: atlasProject,
47+
endpointServiceId: 'endpointServiceId' /*Id of the PrivateEndpointService*/,
48+
profile: 'default',
49+
id: ''
50+
})
51+
```
52+
53+
## Feedback
54+
55+
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::PrivateEndpointAWS`.
56+
57+
- 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-privateendpoint+v1.0.0).
58+
- Issues related to `MongoDB::Atlas::PrivateEndpointAWS` should be reported to the [publisher](https://github.com/mongodb/mongodbatlas-cloudformation-resources/issues).
59+
- Feature requests should be [reported here](https://feedback.mongodb.com/forums/924145-atlas?category_id=392596)
60+
61+
[cdklabs/cdk-cloudformation]: https://github.com/cdklabs/cdk-cloudformation
62+
63+
## License
64+
65+
Distributed under the Apache-2.0 License.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Generated by cdk-import
2+
import * as cdk from "aws-cdk-lib";
3+
import * as constructs from "constructs";
4+
5+
/**
6+
* Creates one private endpoint for the specified cloud service provider. At this current version only AWS is supported
7+
*
8+
* @schema CfnPrivateEndpointAwsProps
9+
*/
10+
export interface CfnPrivateEndpointAwsProps {
11+
/**
12+
* The profile is defined in AWS Secret manager. See [Secret Manager Profile setup (../../../examples/profile-secret.yaml)
13+
*
14+
* @schema CfnPrivateEndpointAwsProps#Profile
15+
*/
16+
readonly profile?: string;
17+
18+
/**
19+
* Unique 24-hexadecimal digit string that identifies your project.
20+
*
21+
* @schema CfnPrivateEndpointAwsProps#ProjectId
22+
*/
23+
readonly projectId: string;
24+
25+
/**
26+
* Unique 24-hexadecimal digit string that identifies the private endpoint service for which you want to create a private endpoint.
27+
*
28+
* @schema CfnPrivateEndpointAwsProps#EndpointServiceId
29+
*/
30+
readonly endpointServiceId: string;
31+
32+
/**
33+
* Unique string that identifies the private endpoint. for AWS is the VPC endpoint ID, example: vpce-xxxxxxxx
34+
*
35+
* @schema CfnPrivateEndpointAwsProps#Id
36+
*/
37+
readonly id?: string;
38+
39+
/**
40+
* If this proper is set to TRUE, the cloud formation resource will return success Only if the private connection is Succeeded
41+
*
42+
* @schema CfnPrivateEndpointAwsProps#EnforceConnectionSuccess
43+
*/
44+
readonly enforceConnectionSuccess?: boolean;
45+
46+
/**
47+
* State of the Amazon Web Service PrivateLink connection when MongoDB Cloud received this request.
48+
*
49+
* @schema CfnPrivateEndpointAwsProps#ConnectionStatus
50+
*/
51+
readonly connectionStatus?: string;
52+
53+
/**
54+
* Error message returned when requesting private connection resource. The resource returns null if the request succeeded.
55+
*
56+
* @schema CfnPrivateEndpointAwsProps#ErrorMessage
57+
*/
58+
readonly errorMessage?: string;
59+
}
60+
61+
/**
62+
* Converts an object of type 'CfnPrivateEndpointAwsProps' to JSON representation.
63+
*/
64+
/* eslint-disable max-len, quote-props */
65+
export function toJson_CfnPrivateEndpointAwsProps(
66+
obj: CfnPrivateEndpointAwsProps | undefined
67+
): Record<string, any> | undefined {
68+
if (obj === undefined) {
69+
return undefined;
70+
}
71+
const result = {
72+
Profile: obj.profile,
73+
ProjectId: obj.projectId,
74+
EndpointServiceId: obj.endpointServiceId,
75+
Id: obj.id,
76+
EnforceConnectionSuccess: obj.enforceConnectionSuccess,
77+
ConnectionStatus: obj.connectionStatus,
78+
ErrorMessage: obj.errorMessage,
79+
};
80+
// filter undefined values
81+
return Object.entries(result).reduce(
82+
(r, i) => (i[1] === undefined ? r : { ...r, [i[0]]: i[1] }),
83+
{}
84+
);
85+
}
86+
/* eslint-enable max-len, quote-props */
87+
88+
/**
89+
* A CloudFormation `MongoDB::Atlas::PrivateEndpointAWS`
90+
*
91+
* @cloudformationResource MongoDB::Atlas::PrivateEndpointAWS
92+
* @stability external
93+
*/
94+
export class CfnPrivateEndpointAws extends cdk.CfnResource {
95+
/**
96+
* The CloudFormation resource type name for this resource class.
97+
*/
98+
public static readonly CFN_RESOURCE_TYPE_NAME =
99+
"MongoDB::Atlas::PrivateEndpointAWS";
100+
101+
/**
102+
* Resource props.
103+
*/
104+
public readonly props: CfnPrivateEndpointAwsProps;
105+
106+
/**
107+
* Create a new `MongoDB::Atlas::PrivateEndpointAWS`.
108+
*
109+
* @param scope - scope in which this resource is defined
110+
* @param id - scoped id of the resource
111+
* @param props - resource properties
112+
*/
113+
constructor(
114+
scope: constructs.Construct,
115+
id: string,
116+
props: CfnPrivateEndpointAwsProps
117+
) {
118+
super(scope, id, {
119+
type: CfnPrivateEndpointAws.CFN_RESOURCE_TYPE_NAME,
120+
properties: toJson_CfnPrivateEndpointAwsProps(props)!,
121+
});
122+
123+
this.props = props;
124+
}
125+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as cdk from "aws-cdk-lib";
2+
import { CfnPrivateEndpointAws } from "./index";
3+
4+
const app = new cdk.App();
5+
const stack = new cdk.Stack(app, "atlas-privateEndpoint", {
6+
env: {
7+
region: process.env.CDK_DEFAULT_REGION,
8+
account: process.env.CDK_DEFAULT_ACCOUNT,
9+
},
10+
});
11+
12+
const atlasProject = "6536c77b1c203c46c251ff0b";
13+
14+
new CfnPrivateEndpointAws(stack, "AtlasPrivateEndpoint", {
15+
projectId: atlasProject,
16+
endpointServiceId: "6536c7814104246bc7d0e940",
17+
profile: "default",
18+
id: "vpce-097276cb6f9eab2f5",
19+
enforceConnectionSuccess: false,
20+
});

0 commit comments

Comments
 (0)