Skip to content

Commit dcc9308

Browse files
feat: Feature/intmdb 1140 cdkl1 for cluster outage (#137)
Co-authored-by: Adelmar92 <[email protected]> Co-authored-by: Adelmar92 <[email protected]>
1 parent 47403ff commit dcc9308

File tree

4 files changed

+304
-1
lines changed

4 files changed

+304
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This example creates a project and a cluster in Atlas using the L1 resources.
2+
import * as cdk from 'aws-cdk-lib';
3+
import { Construct } from 'constructs';
4+
import { CfnClusterOutageSimulation } from 'awscdk-resources-mongodbatlas';
5+
import {FilterCloudProvider} from "../../src/l1-resources/cluster-outage-simulation";
6+
7+
interface AtlasStackProps {
8+
readonly projId: string;
9+
readonly profile: string;
10+
readonly clusterName: string;
11+
readonly provider : FilterCloudProvider;
12+
readonly region : string;
13+
readonly outageType : string;
14+
}
15+
16+
export class CdkTestingStack extends cdk.Stack {
17+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
18+
super(scope, id, props);
19+
20+
const atlasProps = this.getContextProps();
21+
const customDbRole = new CfnClusterOutageSimulation(this, 'CfnClusterOutageSimulation', {
22+
profile: atlasProps.profile,
23+
projectId: atlasProps.projId,
24+
clusterName: atlasProps.clusterName,
25+
filters:[
26+
{
27+
cloudProvider: atlasProps.provider,
28+
region: atlasProps.region,
29+
type: atlasProps.outageType
30+
}
31+
],
32+
});
33+
34+
}
35+
36+
getContextProps(): AtlasStackProps {
37+
const projId = this.node.tryGetContext('projId');
38+
if (!projId){
39+
throw "No context value specified for projId. Please specify via the cdk context."
40+
}
41+
const clusterName = this.node.tryGetContext('clusterName');
42+
const profile = this.node.tryGetContext('profile') ?? 'default';
43+
const provider = this.node.tryGetContext('provider') ?? `AWS`;
44+
const region = this.node.tryGetContext('region') ?? `US_WEST_1`;
45+
const outageType = this.node.tryGetContext('type') ?? 'REGION';
46+
47+
48+
return {
49+
projId,
50+
profile,
51+
clusterName,
52+
provider,
53+
region,
54+
outageType
55+
}
56+
}
57+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# cloud-outage-simulation
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::ClusterOutageSimulation` 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+
This resource allows you to Starts a cluster outage simulation..
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/v2/#tag/Cluster-Outage-Simulation)
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::ClusterOutageSimulation \
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-ClusterOutageSimulation \
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: [cluster-outage-simulation.ts](../../../examples/l1-resources/cluster-outage-simulation.ts)
41+
```ts
42+
import { CfnClusterOutageSimulation } from 'awscdk-resources-mongodbatlas';
43+
44+
const customDbRole = new CfnClusterOutageSimulation(this, 'CfnClusterOutageSimulation', {
45+
profile: atlasProps.profile,
46+
projectId: atlasProps.projId,
47+
clusterName: atlasProps.clusterName,
48+
filters:[
49+
{
50+
cloudProvider: atlasProps.provider,
51+
region: atlasProps.region,
52+
type: atlasProps.outageType
53+
}
54+
],
55+
});
56+
```
57+
58+
59+
## Feedback
60+
61+
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::ClusterOutageSimulation`.
62+
63+
* 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-clusteroutagesimulationt+v1.0.0).
64+
* Issues related to `MongoDB::Atlas::ClusterOutageSimulation` should be reported to the [publisher](https://github.com/mongodb/mongodbatlas-cloudformation-resources/issues).
65+
* Feature requests should be [reported here](https://feedback.mongodb.com/forums/924145-atlas?category_id=392596)
66+
67+
[cdklabs/cdk-cloudformation]: https://github.com/cdklabs/cdk-cloudformation
68+
69+
## License
70+
71+
Distributed under the Apache-2.0 License.
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
// Generated by cdk-import
2+
import * as cdk from "aws-cdk-lib";
3+
import * as constructs from "constructs";
4+
5+
/**
6+
* An example resource schema demonstrating some basic constructs and validation rules.
7+
*
8+
* @schema CfnClusterOutageSimulationProps
9+
*/
10+
export interface CfnClusterOutageSimulationProps {
11+
/**
12+
* The profile is defined in AWS Secret manager. See [Secret Manager Profile setup](../../../examples/profile-secret.yaml).
13+
*
14+
* @schema CfnClusterOutageSimulationProps#Profile
15+
*/
16+
readonly profile: string;
17+
18+
/**
19+
* 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.
20+
*
21+
* @schema CfnClusterOutageSimulationProps#OutageFilters
22+
*/
23+
readonly outageFilters: Filter[];
24+
25+
/**
26+
* Human-readable label that identifies the project.
27+
*
28+
* @schema CfnClusterOutageSimulationProps#ProjectId
29+
*/
30+
readonly projectId: string;
31+
32+
/**
33+
* Human-readable label that identifies the cluster .
34+
*
35+
* @schema CfnClusterOutageSimulationProps#ClusterName
36+
*/
37+
readonly clusterName: string;
38+
}
39+
40+
/**
41+
* Converts an object of type 'CfnClusterOutageSimulationProps' to JSON representation.
42+
*/
43+
/* eslint-disable max-len, quote-props */
44+
export function toJson_CfnClusterOutageSimulationProps(
45+
obj: CfnClusterOutageSimulationProps | undefined
46+
): Record<string, any> | undefined {
47+
if (obj === undefined) {
48+
return undefined;
49+
}
50+
const result = {
51+
Profile: obj.profile,
52+
OutageFilters: obj.outageFilters?.map((y) => toJson_Filter(y)),
53+
ProjectId: obj.projectId,
54+
ClusterName: obj.clusterName,
55+
};
56+
// filter undefined values
57+
return Object.entries(result).reduce(
58+
(r, i) => (i[1] === undefined ? r : { ...r, [i[0]]: i[1] }),
59+
{}
60+
);
61+
}
62+
/* eslint-enable max-len, quote-props */
63+
64+
/**
65+
* @schema Filter
66+
*/
67+
export interface Filter {
68+
/**
69+
* @schema Filter#CloudProvider
70+
*/
71+
readonly cloudProvider?: FilterCloudProvider;
72+
73+
/**
74+
* @schema Filter#Region
75+
*/
76+
readonly region?: string;
77+
78+
/**
79+
* @schema Filter#Type
80+
*/
81+
readonly type?: string;
82+
}
83+
84+
/**
85+
* Converts an object of type 'Filter' to JSON representation.
86+
*/
87+
/* eslint-disable max-len, quote-props */
88+
export function toJson_Filter(
89+
obj: Filter | undefined
90+
): Record<string, any> | undefined {
91+
if (obj === undefined) {
92+
return undefined;
93+
}
94+
const result = {
95+
CloudProvider: obj.cloudProvider,
96+
Region: obj.region,
97+
Type: obj.type,
98+
};
99+
// filter undefined values
100+
return Object.entries(result).reduce(
101+
(r, i) => (i[1] === undefined ? r : { ...r, [i[0]]: i[1] }),
102+
{}
103+
);
104+
}
105+
/* eslint-enable max-len, quote-props */
106+
107+
/**
108+
* @schema FilterCloudProvider
109+
*/
110+
export enum FilterCloudProvider {
111+
/** AWS */
112+
AWS = "AWS",
113+
/** AZURE */
114+
AZURE = "AZURE",
115+
/** GCP */
116+
GCP = "GCP",
117+
}
118+
119+
/**
120+
* A CloudFormation `MongoDB::Atlas::ClusterOutageSimulation`
121+
*
122+
* @cloudformationResource MongoDB::Atlas::ClusterOutageSimulation
123+
* @stability external
124+
*/
125+
export class CfnClusterOutageSimulation extends cdk.CfnResource {
126+
/**
127+
* The CloudFormation resource type name for this resource class.
128+
*/
129+
public static readonly CFN_RESOURCE_TYPE_NAME =
130+
"MongoDB::Atlas::ClusterOutageSimulation";
131+
132+
/**
133+
* Resource props.
134+
*/
135+
public readonly props: CfnClusterOutageSimulationProps;
136+
137+
/**
138+
* Attribute `MongoDB::Atlas::ClusterOutageSimulation.SimulationId`
139+
*/
140+
public readonly attrSimulationId: string;
141+
/**
142+
* Attribute `MongoDB::Atlas::ClusterOutageSimulation.StartRequestDate`
143+
*/
144+
public readonly attrStartRequestDate: string;
145+
/**
146+
* Attribute `MongoDB::Atlas::ClusterOutageSimulation.State`
147+
*/
148+
public readonly attrState: string;
149+
150+
/**
151+
* Create a new `MongoDB::Atlas::ClusterOutageSimulation`.
152+
*
153+
* @param scope - scope in which this resource is defined
154+
* @param id - scoped id of the resource
155+
* @param props - resource properties
156+
*/
157+
constructor(
158+
scope: constructs.Construct,
159+
id: string,
160+
props: CfnClusterOutageSimulationProps
161+
) {
162+
super(scope, id, {
163+
type: CfnClusterOutageSimulation.CFN_RESOURCE_TYPE_NAME,
164+
properties: toJson_CfnClusterOutageSimulationProps(props)!,
165+
});
166+
167+
this.props = props;
168+
169+
this.attrSimulationId = cdk.Token.asString(this.getAtt("SimulationId"));
170+
this.attrStartRequestDate = cdk.Token.asString(
171+
this.getAtt("StartRequestDate")
172+
);
173+
this.attrState = cdk.Token.asString(this.getAtt("State"));
174+
}
175+
}

0 commit comments

Comments
 (0)