-
Notifications
You must be signed in to change notification settings - Fork 16
/
custom-db-role.ts
59 lines (52 loc) · 1.57 KB
/
custom-db-role.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
// 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 { CfnCustomDbRole } from 'awscdk-resources-mongodbatlas';
interface AtlasStackProps {
readonly projId: string;
readonly profile: string;
readonly roleName: string;
readonly dbName: string;
readonly collectionName: string;
}
export class CdkTestingStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const atlasProps = this.getContextProps();
const customDbRole = new CfnCustomDbRole(this, 'CustomDbRole', {
projectId: atlasProps.projId,
profile: atlasProps.profile,
actions:[
{
action: "GROUP_READ",
resources: [
{
collection: atlasProps.collectionName,
},
{
db: atlasProps.dbName,
}
]
}
],
roleName: atlasProps.roleName,
});
}
getContextProps(): AtlasStackProps {
const projId = this.node.tryGetContext('projId');
if (!projId){
throw "No context value specified for projId. Please specify via the cdk context."
}
const roleName = this.node.tryGetContext('roleName');
const profile = this.node.tryGetContext('profile') ?? 'default';
const dbName = this.node.tryGetContext('dbName');
const collectionName = this.node.tryGetContext('collectionName');
return {
projId,
profile,
roleName,
dbName,
collectionName
}
}
}