Skip to content

Commit caf57eb

Browse files
feat: Adds new SearchDeployment L1 construct (#232)
1 parent c7ed5e5 commit caf57eb

File tree

8 files changed

+1106
-1
lines changed

8 files changed

+1106
-1
lines changed

API.md

Lines changed: 771 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This example creates a search deployment in Atlas using the L1 resource.
2+
import * as cdk from 'aws-cdk-lib';
3+
import { Construct } from 'constructs';
4+
import { CfnSearchDeployment } from 'awscdk-resources-mongodbatlas';
5+
6+
interface AtlasStackProps {
7+
readonly projectId: string;
8+
readonly profile: string;
9+
readonly clusterName: string;
10+
}
11+
12+
export class CdkTestingStack extends cdk.Stack {
13+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
14+
super(scope, id, props);
15+
16+
const atlasProps = this.getContextProps();
17+
const searchDeployment = new CfnSearchDeployment(this, 'CfnSearchDeployment', {
18+
profile: atlasProps.profile,
19+
clusterName: atlasProps.clusterName,
20+
projectId: atlasProps.projectId,
21+
specs: [
22+
{
23+
instanceSize: "S30_HIGHCPU_NVME",
24+
nodeCount: 2,
25+
},
26+
]
27+
});
28+
29+
}
30+
31+
getContextProps(): AtlasStackProps {
32+
const profile = this.node.tryGetContext('profile') ?? 'default';
33+
const projectId = this.node.tryGetContext('projectId');
34+
if (!projectId){
35+
throw "No context value specified for projectId. Please specify via the cdk context."
36+
}
37+
const clusterName = this.node.tryGetContext('clusterName');
38+
if (!projectId){
39+
throw "No context value specified for clusterName. Please specify via the cdk context."
40+
}
41+
42+
return {
43+
projectId,
44+
profile,
45+
clusterName
46+
}
47+
}
48+
49+
}

src/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ L1 constructs are called Cfn (short for CloudFormation) resources. These resourc
3838
| project | Retrieves or creates projects in any given Atlas organization. | [README.md](l1-resources/project/README.md) |
3939
| project-invitation | Returns, send project invitations. | [README.md](l1-resources/project-invitation/README.md) |
4040
| project-ip-access-list | Returns, adds, edits, and removes network access limits to database deployments in MongoDB Cloud. | [README.md](l1-resources/project-ip-access-list/README.md) |
41+
| search-deployment | The resource lets you create, edit and delete dedicated search nodes in a cluster. | [README.md](l1-resources/search-deployment/README.md) |
4142
| search-index | Returns, adds, edits, and removes Atlas Search indexes. Also returns and updates user-defined analyzers. | [README.md](l1-resources/search-index/README.md) |
4243
| serverless-instance | Returns, adds, edits, and removes serverless instances. | [README.md](l1-resources/serverless-instance/README.md) |
4344
| teams | Adds one team to the specified project. All members of the team share the same project access. To use this resource, the requesting API Key must have the Project User Admin role. This resource doesn't require the API Key to have an Access List. | [README.md](l1-resources/teams/README.md) |

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ export {
308308
ListOptions,
309309
} from "./l1-resources/project-ip-access-list";
310310

311+
export {
312+
CfnSearchDeployment,
313+
CfnSearchDeploymentProps,
314+
ApiSearchDeploymentSpec,
315+
} from "./l1-resources/search-deployment";
316+
311317
export {
312318
ApiAtlasFtsAnalyzersViewManual,
313319
ApiAtlasFtsMappingsViewManual,
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# search-deployment
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::SearchDeployment`.
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+
Retrieves or creates projects in any given Atlas organization.
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/Projects)
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::SearchDeployment \
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-SearchDeployment \
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: [search-deployment.ts](../../../examples/l1-resources/search-deployment.ts)
41+
```ts
42+
import { CfnSearchDeployment } from 'awscdk-resources-mongodbatlas';
43+
44+
const searchDeployment = new CfnSearchDeployment(this, 'CfnSearchDeployment', {
45+
profile: atlasProps.profile,
46+
clusterName: atlasProps.clusterName,
47+
projectId: atlasProps.projectId,
48+
specs: [
49+
{
50+
instanceSize: "S30_HIGHCPU_NVME",
51+
nodeCount: 2,
52+
},
53+
]
54+
});
55+
```
56+
57+
## Feedback
58+
59+
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::SearchDeployment`.
60+
61+
* 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-project+v1.0.0).
62+
* Issues related to `MongoDB::Atlas::SearchDeployment` should be reported to the [publisher](https://github.com/mongodb/mongodbatlas-cloudformation-resources/issues).
63+
* Feature requests should be [reported here](https://feedback.mongodb.com/forums/924145-atlas?category_id=392596)
64+
65+
[cdklabs/cdk-cloudformation]: https://github.com/cdklabs/cdk-cloudformation
66+
67+
## License
68+
69+
Distributed under the Apache-2.0 License.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// Generated by cdk-import
2+
import * as cdk from "aws-cdk-lib";
3+
import * as constructs from "constructs";
4+
5+
/**
6+
* The resource lets you create, edit and delete dedicated search nodes in a cluster. For details on supported cloud providers and existing limitations you can visit the Search Node Documentation: https://www.mongodb.com/docs/atlas/cluster-config/multi-cloud-distribution/#search-nodes-for-workload-isolation. Only a single search deployment resource can be defined for each cluster.
7+
*
8+
* @schema CfnSearchDeploymentProps
9+
*/
10+
export interface CfnSearchDeploymentProps {
11+
/**
12+
* Profile used to provide credentials information, (a secret with the cfn/atlas/profile/{Profile}, is required), if not provided default is used
13+
*
14+
* @schema CfnSearchDeploymentProps#Profile
15+
*/
16+
readonly profile?: string;
17+
18+
/**
19+
* Label that identifies the cluster to return the search nodes for.
20+
*
21+
* @schema CfnSearchDeploymentProps#ClusterName
22+
*/
23+
readonly clusterName: string;
24+
25+
/**
26+
* Unique 24-hexadecimal character string that identifies the project.
27+
*
28+
* @schema CfnSearchDeploymentProps#ProjectId
29+
*/
30+
readonly projectId: string;
31+
32+
/**
33+
* List of settings that configure the search nodes for your cluster. This list is currently limited to defining a single element.
34+
*
35+
* @schema CfnSearchDeploymentProps#Specs
36+
*/
37+
readonly specs: ApiSearchDeploymentSpec[];
38+
}
39+
40+
/**
41+
* Converts an object of type 'CfnSearchDeploymentProps' to JSON representation.
42+
*/
43+
/* eslint-disable max-len, quote-props */
44+
export function toJson_CfnSearchDeploymentProps(
45+
obj: CfnSearchDeploymentProps | undefined
46+
): Record<string, any> | undefined {
47+
if (obj === undefined) {
48+
return undefined;
49+
}
50+
const result = {
51+
Profile: obj.profile,
52+
ClusterName: obj.clusterName,
53+
ProjectId: obj.projectId,
54+
Specs: obj.specs?.map((y) => toJson_ApiSearchDeploymentSpec(y)),
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 ApiSearchDeploymentSpec
66+
*/
67+
export interface ApiSearchDeploymentSpec {
68+
/**
69+
* Hardware specification for the search node instance sizes. The [MongoDB Atlas API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Atlas-Search/operation/createAtlasSearchDeployment) describes the valid values. More details can also be found in the [Search Node Documentation](https://www.mongodb.com/docs/atlas/cluster-config/multi-cloud-distribution/#search-tier).
70+
*
71+
* @schema ApiSearchDeploymentSpec#InstanceSize
72+
*/
73+
readonly instanceSize: string;
74+
75+
/**
76+
* Number of search nodes in the cluster.
77+
*
78+
* @schema ApiSearchDeploymentSpec#NodeCount
79+
*/
80+
readonly nodeCount: number;
81+
}
82+
83+
/**
84+
* Converts an object of type 'ApiSearchDeploymentSpec' to JSON representation.
85+
*/
86+
/* eslint-disable max-len, quote-props */
87+
export function toJson_ApiSearchDeploymentSpec(
88+
obj: ApiSearchDeploymentSpec | undefined
89+
): Record<string, any> | undefined {
90+
if (obj === undefined) {
91+
return undefined;
92+
}
93+
const result = {
94+
InstanceSize: obj.instanceSize,
95+
NodeCount: obj.nodeCount,
96+
};
97+
// filter undefined values
98+
return Object.entries(result).reduce(
99+
(r, i) => (i[1] === undefined ? r : { ...r, [i[0]]: i[1] }),
100+
{}
101+
);
102+
}
103+
/* eslint-enable max-len, quote-props */
104+
105+
/**
106+
* A CloudFormation `MongoDB::Atlas::SearchDeployment`
107+
*
108+
* @cloudformationResource MongoDB::Atlas::SearchDeployment
109+
* @stability external
110+
*/
111+
export class CfnSearchDeployment extends cdk.CfnResource {
112+
/**
113+
* The CloudFormation resource type name for this resource class.
114+
*/
115+
public static readonly CFN_RESOURCE_TYPE_NAME =
116+
"MongoDB::Atlas::SearchDeployment";
117+
118+
/**
119+
* Resource props.
120+
*/
121+
public readonly props: CfnSearchDeploymentProps;
122+
123+
/**
124+
* Attribute `MongoDB::Atlas::SearchDeployment.Id`
125+
*/
126+
public readonly attrId: string;
127+
/**
128+
* Attribute `MongoDB::Atlas::SearchDeployment.StateName`
129+
*/
130+
public readonly attrStateName: string;
131+
132+
/**
133+
* Create a new `MongoDB::Atlas::SearchDeployment`.
134+
*
135+
* @param scope - scope in which this resource is defined
136+
* @param id - scoped id of the resource
137+
* @param props - resource properties
138+
*/
139+
constructor(
140+
scope: constructs.Construct,
141+
id: string,
142+
props: CfnSearchDeploymentProps
143+
) {
144+
super(scope, id, {
145+
type: CfnSearchDeployment.CFN_RESOURCE_TYPE_NAME,
146+
properties: toJson_CfnSearchDeploymentProps(props)!,
147+
});
148+
149+
this.props = props;
150+
151+
this.attrId = cdk.Token.asString(this.getAtt("Id"));
152+
this.attrStateName = cdk.Token.asString(this.getAtt("StateName"));
153+
}
154+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2024 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { App, Stack } from "aws-cdk-lib";
16+
import { Template } from "aws-cdk-lib/assertions";
17+
import { CfnSearchDeployment } from "../../../src";
18+
19+
const RESOURCE_NAME = "MongoDB::Atlas::SearchDeployment";
20+
const PROJECT_ID = "63350255419cf25e3d511c95";
21+
const PROFILE = "some-profile";
22+
const CLUSTER_NAME = "Cluster0";
23+
const INSTANCE_SIZE = "S30_HIGHCPU_NVME";
24+
const NODE_COUNT = 3;
25+
26+
test("CfnSearchDeployment construct should contain default properties", () => {
27+
const mockApp = new App();
28+
const stack = new Stack(mockApp);
29+
30+
new CfnSearchDeployment(stack, "testing-stack", {
31+
profile: PROFILE,
32+
clusterName: CLUSTER_NAME,
33+
projectId: PROJECT_ID,
34+
specs: [
35+
{
36+
instanceSize: INSTANCE_SIZE,
37+
nodeCount: NODE_COUNT,
38+
},
39+
],
40+
});
41+
42+
const template = Template.fromStack(stack);
43+
44+
template.hasResourceProperties(RESOURCE_NAME, {
45+
Profile: PROFILE,
46+
ClusterName: CLUSTER_NAME,
47+
ProjectId: PROJECT_ID,
48+
Specs: [
49+
{
50+
InstanceSize: INSTANCE_SIZE,
51+
NodeCount: NODE_COUNT,
52+
},
53+
],
54+
});
55+
});

0 commit comments

Comments
 (0)