-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcluster.ts
92 lines (84 loc) · 2.69 KB
/
cluster.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// This example creates a project and a cluster in Atlas using the L1 resources.
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { CfnProject, CfnCluster } from 'awscdk-resources-mongodbatlas';
interface AtlasStackProps {
readonly orgId: string;
readonly profile: string;
readonly projName: string;
readonly clusterName: string;
readonly clusterType: string;
readonly instanceSize: string;
readonly region: string;
}
export class CdkTestingStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const atlasProps = this.getContextProps();
const projectRes = new CfnProject(this, 'ProjectResource', {
name: atlasProps.projName,
orgId: atlasProps.orgId,
profile: atlasProps.profile
});
const clusterRes = new CfnCluster(this, 'ClusterResource', {
name: atlasProps.clusterName,
projectId: projectRes.attrId,
profile: atlasProps.profile,
clusterType: atlasProps.clusterType,
backupEnabled: true,
pitEnabled: false,
replicationSpecs: [{
numShards: 1,
advancedRegionConfigs: [{
autoScaling: {
diskGb: {
enabled: true,
},
compute: {
enabled: false,
scaleDownEnabled: false,
},
},
analyticsSpecs: {
ebsVolumeType: "STANDARD",
instanceSize: atlasProps.instanceSize,
nodeCount: 3,
},
electableSpecs: {
ebsVolumeType: "STANDARD",
instanceSize: atlasProps.instanceSize,
nodeCount: 3,
},
readOnlySpecs: {
ebsVolumeType: "STANDARD",
instanceSize: atlasProps.instanceSize,
nodeCount: 3,
},
priority: 7,
regionName: atlasProps.region,
}]
}]
});
}
getContextProps(): AtlasStackProps {
const orgId = this.node.tryGetContext('orgId');
if (!orgId){
throw "No context value specified for orgId. Please specify via the cdk context."
}
const projName = this.node.tryGetContext('projName') ?? 'test-proj';
const profile = this.node.tryGetContext('profile') ?? 'default';
const clusterName = this.node.tryGetContext('clusterName') ?? 'test-cluster';
const clusterType = this.node.tryGetContext('clusterType') ?? 'REPLICASET';
const instanceSize = this.node.tryGetContext('instanceSize') ?? "M10";
const region = this.node.tryGetContext('region') ?? "US_EAST_1";
return {
projName,
orgId,
profile,
clusterName,
clusterType,
instanceSize,
region,
}
}
}