Skip to content

Commit 47403ff

Browse files
feat: Feature/intmdb 1055 cdkl1 org (#128)
Co-authored-by: Adelmar92 <[email protected]> Co-authored-by: Adelmar92 <[email protected]>
1 parent 167fb46 commit 47403ff

File tree

6 files changed

+325
-1
lines changed

6 files changed

+325
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
import * as cdk from 'aws-cdk-lib';
3+
import { Construct } from 'constructs';
4+
import { CfnOrganization, CfnOrganizationPropsRoles } from 'awscdk-resources-mongodbatlas';
5+
6+
interface AtlasStackProps {
7+
readonly orgOwnerId: string;
8+
readonly profile: string;
9+
readonly name: string;
10+
readonly awsSecretName: string;
11+
}
12+
13+
interface apiKey{
14+
readonly roles: string[];
15+
readonly description: string;
16+
}
17+
18+
export class CdkTestingStack extends cdk.Stack {
19+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
20+
super(scope, id, props);
21+
22+
const atlasProps = this.getContextProps();
23+
24+
const myOrg = new CfnOrganization(this, 'MyOrganization', {
25+
orgId: atlasProps.orgOwnerId,
26+
profile: atlasProps.profile,
27+
username: atlasProps.name,
28+
awsSecretName: [atlasProps.awsSecretName],
29+
apikey:{
30+
roles: ["ORG_OWNER"],
31+
description: "test-cdk"
32+
}
33+
34+
});
35+
}
36+
37+
getContextProps(): AtlasStackProps {
38+
const orgOwnerId = this.node.tryGetContext('orgOwnerId');
39+
if (!orgOwnerId){
40+
throw "No context value specified for orgOwnerId. Please specify via the cdk context."
41+
}
42+
const name = this.node.tryGetContext('name') ?? 'test-org-cdk';
43+
const awsSecretName = this.node.tryGetContext('awsSecretName') ?? 'cfn/atlas/profile/org-retest';
44+
const profile = this.node.tryGetContext('profile') ?? 'default';
45+
46+
return {
47+
orgOwnerId,
48+
profile,
49+
name,
50+
awsSecretName,
51+
}
52+
}
53+
}

scripts/cdk.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ for file in "${dir}"/mongodb-atlas-*.json; do
5757
rm -rf l1-resources/"${path}"/src/*.ts
5858
fi
5959

60+
# NOTE: known_issue MODULE_NOT_FOUND error.
61+
# When the Resource is not merged to main branch of submodule, you see the above error.
6062
cdk-import cfn -l typescript -s "${file}" -o "src/l1-resources/${path}" "${src}"
6163
# need rename resource file to index.ts file
6264
mv "src/l1-resources/${path}/mongodb-atlas-${path//-/}.ts" "src/l1-resources/${path}/index.ts"

src/l1-resources/encryption-at-rest/integ.default.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const stack = new cdk.Stack(app, "atlas-EncAtRest-cdk-test", {
1111

1212
const projectId =
1313
stack.node.tryGetContext("MONGODB_PROJECT_ID") ||
14-
process.env.MONGODB_ATLAS_ORG_ID;
14+
process.env.MONGODB_ATLAS_PROJECT_ID;
1515
const customerMasterKeyId =
1616
stack.node.tryGetContext("CUSTOMER_MASTER_KEY_ID") ||
1717
process.env.CUSTOMER_MASTER_KEY_ID;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# organization
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::Organization` 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+
Returns, adds, and edits organizational units in MongoDB Cloud.
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/Organizations)
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::Organization \
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-Organization \
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: [organization.ts](../../../examples/l1-resources/organization.ts)
41+
```ts
42+
import { CfnOrganization } from 'awscdk-resources-mongodbatlas';
43+
44+
const myOrg = new CfnOrganization(this, 'MyOrg', {
45+
orgOwnerId: atlasProps.orgOwnerId,
46+
profile: atlasProps.profile,
47+
name: atlasProps.name,
48+
awsSecretName: [atlasProps.awsSecretName],
49+
apikey:{
50+
roles: ["ORG_OWNER"],
51+
description:"creating an organization for development"
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::Organization`.
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-organization+v1.0.0).
62+
* Issues related to `MongoDB::Atlas::Organization` 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: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// Generated by cdk-import
2+
import * as cdk from "aws-cdk-lib";
3+
import * as constructs from "constructs";
4+
5+
/**
6+
* Returns, adds, and edits organizational units in MongoDB Cloud.
7+
*
8+
* @schema CfnOrganizationProps
9+
*/
10+
export interface CfnOrganizationProps {
11+
/**
12+
* Human-readable label that identifies the organization.
13+
*
14+
* @schema CfnOrganizationProps#Name
15+
*/
16+
readonly name: string;
17+
18+
/**
19+
* @schema CfnOrganizationProps#APIKey
20+
*/
21+
readonly apiKey?: ApiKey;
22+
23+
/**
24+
* Unique 24-hexadecimal digit string that identifies the federation to link the newly created organization to. If specified, the proposed Organization Owner of the new organization must have the Organization Owner role in an organization associated with the federation.
25+
*
26+
* @schema CfnOrganizationProps#FederatedSettingsId
27+
*/
28+
readonly federatedSettingsId?: string;
29+
30+
/**
31+
* Unique 24-hexadecimal digit string that identifies the MongoDB Cloud user that you want to assign the Organization Owner role. This user must be a member of the same organization as the calling API key. If you provide federationSettingsId, this user must instead have the Organization Owner role on an organization in the specified federation. This parameter is required only when you authenticate with Programmatic API Keys.
32+
*
33+
* @schema CfnOrganizationProps#OrgOwnerId
34+
*/
35+
readonly orgOwnerId: string;
36+
37+
/**
38+
* Profile used to provide credentials information, (a secret with the cfn/atlas/profile/{Profile}, is required), if not provided default is used
39+
*
40+
* @schema CfnOrganizationProps#Profile
41+
*/
42+
readonly profile?: string;
43+
44+
/**
45+
* AwsSecretName used to set newly created Org credentials information.
46+
*
47+
* @schema CfnOrganizationProps#AwsSecretName
48+
*/
49+
readonly awsSecretName: string;
50+
51+
/**
52+
* Flag that indicates whether this organization has been deleted.
53+
*
54+
* @schema CfnOrganizationProps#IsDeleted
55+
*/
56+
readonly isDeleted?: boolean;
57+
}
58+
59+
/**
60+
* Converts an object of type 'CfnOrganizationProps' to JSON representation.
61+
*/
62+
/* eslint-disable max-len, quote-props */
63+
export function toJson_CfnOrganizationProps(
64+
obj: CfnOrganizationProps | undefined
65+
): Record<string, any> | undefined {
66+
if (obj === undefined) {
67+
return undefined;
68+
}
69+
const result = {
70+
Name: obj.name,
71+
APIKey: toJson_ApiKey(obj.apiKey),
72+
FederatedSettingsId: obj.federatedSettingsId,
73+
OrgOwnerId: obj.orgOwnerId,
74+
Profile: obj.profile,
75+
AwsSecretName: obj.awsSecretName,
76+
IsDeleted: obj.isDeleted,
77+
};
78+
// filter undefined values
79+
return Object.entries(result).reduce(
80+
(r, i) => (i[1] === undefined ? r : { ...r, [i[0]]: i[1] }),
81+
{}
82+
);
83+
}
84+
/* eslint-enable max-len, quote-props */
85+
86+
/**
87+
* @schema APIKey
88+
*/
89+
export interface ApiKey {
90+
/**
91+
* Purpose or explanation provided when someone created this organization API key. 1 to 250 characters
92+
*
93+
* @schema APIKey#Description
94+
*/
95+
readonly description?: string;
96+
97+
/**
98+
* List of roles to grant this API key. If you provide this list, provide a minimum of one role and ensure each role applies to this organization.
99+
*
100+
* @schema APIKey#Roles
101+
*/
102+
readonly roles?: string[];
103+
}
104+
105+
/**
106+
* Converts an object of type 'ApiKey' to JSON representation.
107+
*/
108+
/* eslint-disable max-len, quote-props */
109+
export function toJson_ApiKey(
110+
obj: ApiKey | undefined
111+
): Record<string, any> | undefined {
112+
if (obj === undefined) {
113+
return undefined;
114+
}
115+
const result = {
116+
Description: obj.description,
117+
Roles: obj.roles?.map((y) => y),
118+
};
119+
// filter undefined values
120+
return Object.entries(result).reduce(
121+
(r, i) => (i[1] === undefined ? r : { ...r, [i[0]]: i[1] }),
122+
{}
123+
);
124+
}
125+
/* eslint-enable max-len, quote-props */
126+
127+
/**
128+
* A CloudFormation `MongoDB::Atlas::Organization`
129+
*
130+
* @cloudformationResource MongoDB::Atlas::Organization
131+
* @stability external
132+
*/
133+
export class CfnOrganization extends cdk.CfnResource {
134+
/**
135+
* The CloudFormation resource type name for this resource class.
136+
*/
137+
public static readonly CFN_RESOURCE_TYPE_NAME =
138+
"MongoDB::Atlas::Organization";
139+
140+
/**
141+
* Resource props.
142+
*/
143+
public readonly props: CfnOrganizationProps;
144+
145+
/**
146+
* Attribute `MongoDB::Atlas::Organization.OrgId`
147+
*/
148+
public readonly attrOrgId: string;
149+
150+
/**
151+
* Create a new `MongoDB::Atlas::Organization`.
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: CfnOrganizationProps
161+
) {
162+
super(scope, id, {
163+
type: CfnOrganization.CFN_RESOURCE_TYPE_NAME,
164+
properties: toJson_CfnOrganizationProps(props)!,
165+
});
166+
167+
this.props = props;
168+
169+
this.attrOrgId = cdk.Token.asString(this.getAtt("OrgId"));
170+
}
171+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as cdk from "aws-cdk-lib";
2+
import { CfnOrganization } from "./index";
3+
4+
const app = new cdk.App();
5+
const stack = new cdk.Stack(app, "atlas-organization-cdk-test", {
6+
env: {
7+
region: process.env.CDK_DEFAULT_REGION,
8+
account: process.env.CDK_DEFAULT_ACCOUNT,
9+
},
10+
});
11+
12+
const awsSecretName =
13+
stack.node.tryGetContext("AWS_SECRET_NAME") || process.env.AWS_SECRET_NAME;
14+
const orgOwnerId =
15+
stack.node.tryGetContext("MONGODB_ATLAS_ORG_OWNER_ID") ||
16+
process.env.MONGODB_ATLAS_ORG_OWNER_ID;
17+
const name = stack.node.tryGetContext("NAME") || process.env.NAME;
18+
const profile = stack.node.tryGetContext("PROFILE") || process.env.PROFILE;
19+
20+
new CfnOrganization(stack, "organization", {
21+
name: name,
22+
orgOwnerId: orgOwnerId,
23+
awsSecretName: awsSecretName,
24+
profile: profile,
25+
apiKey: {
26+
roles: ["ORG_OWNER"],
27+
description: "test-cdk",
28+
},
29+
});

0 commit comments

Comments
 (0)