-
Notifications
You must be signed in to change notification settings - Fork 16
/
atlas-basic.ts
78 lines (70 loc) · 2.26 KB
/
atlas-basic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// This CDK L3 example creates a MongoDB Atlas project, cluster, databaseUser, and projectIpAccessList
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { AtlasBasic } from 'awscdk-resources-mongodbatlas';
interface AtlasStackProps {
readonly orgId: string;
readonly profile: string;
readonly clusterName: string;
readonly region: string;
readonly ip: string;
}
export class CdkTestingStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const atlasProps = this.getContextProps();
const atlasBasic = new AtlasBasic(this, 'AtlasBasic', {
clusterProps: {
name: atlasProps.clusterName,
replicationSpecs: [
{
numShards: 1,
advancedRegionConfigs: [
{
analyticsSpecs: {
ebsVolumeType: "STANDARD",
instanceSize: "M10",
nodeCount: 1
},
electableSpecs: {
ebsVolumeType: "STANDARD",
instanceSize: "M10",
nodeCount: 3
},
priority: 7,
regionName: atlasProps.region,
}]
}]
},
projectProps: {
orgId: atlasProps.orgId,
},
ipAccessListProps: {
accessList:[
{ ipAddress: atlasProps.ip, comment: 'My first IP address' }
]
},
profile: atlasProps.profile,
});
}
getContextProps(): AtlasStackProps {
const orgId = this.node.tryGetContext('orgId');
if (!orgId){
throw "No context value specified for orgId. Please specify via the cdk context."
}
const profile = this.node.tryGetContext('profile') ?? 'default';
const clusterName = this.node.tryGetContext('clusterName') ?? 'test-cluster';
const region = this.node.tryGetContext('region') ?? "US_EAST_1";
const ip = this.node.tryGetContext('ip');
if (!ip){
throw "No context value specified for ip. Please specify via the cdk context."
}
return {
orgId,
profile,
clusterName,
region,
ip
}
}
}