-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
74 lines (65 loc) · 1.96 KB
/
index.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
#!/usr/bin/env node
import 'source-map-support/register';
import { App, CfnOutput, Stack } from 'aws-cdk-lib';
import { SSMClient, GetParameterCommand, ParameterNotFound } from "@aws-sdk/client-ssm";
import { OcElasticsearchStack, OcElasticsearchProps } from './lib/oc-elasticsearch-stack';
function bye(msg: string, exitCode: number): void {
console.log(msg);
process.exit(exitCode);
}
const ocElasticsearchEnv = process.env.OC_ELASTICSEARCH_ENVIRONMENT || '';
if (!ocElasticsearchEnv) bye('You must set OC_ELASTICSEARCH_ENVIRONMENT!', 1);
async function getCdkConfig(): Promise<OcElasticsearchProps | undefined> {
const client = new SSMClient({});
const configParameterName = `/oc-elasticsearch-cdk/config/${ocElasticsearchEnv}`;
const getConfigCommand = new GetParameterCommand({
Name: configParameterName,
WithDecryption: true,
});
try {
const resp = await client.send(getConfigCommand);
if (resp.Parameter) {
return JSON.parse(resp.Parameter.Value || '{}');
}
} catch (error) {
if (error instanceof ParameterNotFound) {
throw new Error(`Parameter ${configParameterName} not found!`);
} else {
console.log(error);
}
}
}
async function main(): Promise<void> {
const config = await getCdkConfig();
if (!config) {
bye('Failed fetching config', 1);
} else {
console.log(config);
const {
esDomainName,
notificationEmail,
notificationSlackUrl,
deploymentType,
vpcCidr,
} = config;
const app = new App();
new OcElasticsearchStack(app, `${esDomainName}-stack`, {
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
},
esDomainName,
deploymentType,
vpcCidr,
notificationEmail,
notificationSlackUrl,
tags: {
project: 'MH',
department: 'DE',
product: 'opencast-elasticsearch',
deploy_environment: ocElasticsearchEnv,
}
});
}
}
main();