Skip to content

Commit b540c29

Browse files
committed
refactor: extract iacStack to define resrouces separately
Signed-off-by: seven <[email protected]>
1 parent 95b8bce commit b540c29

File tree

12 files changed

+334
-268
lines changed

12 files changed

+334
-268
lines changed

src/parser/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const validateExistence = (path: string) => {
1313
}
1414
};
1515

16-
const transformYaml = (iacJson: ServerlessIacRaw, context: ActionContext): ServerlessIac => {
16+
const transformYaml = (iacJson: ServerlessIacRaw): ServerlessIac => {
1717
return {
1818
service: iacJson.service,
1919
version: iacJson.version,
@@ -23,7 +23,7 @@ const transformYaml = (iacJson: ServerlessIacRaw, context: ActionContext): Serve
2323
functions: parseFunction(iacJson.functions),
2424
events: parseEvent(iacJson.events),
2525
databases: parseDatabase(iacJson.databases),
26-
tags: parseTag(iacJson.tags, context),
26+
tags: parseTag(iacJson.tags),
2727
};
2828
};
2929

@@ -35,5 +35,5 @@ export const parseYaml = (context: ActionContext): ServerlessIac => {
3535

3636
validateYaml(iacJson);
3737

38-
return transformYaml(iacJson, context);
38+
return transformYaml(iacJson);
3939
};

src/parser/tagParser.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import { ActionContext, TagDomain, Tags } from '../types';
2-
import { replaceReference } from '../common';
1+
import { TagDomain, Tags } from '../types';
32

4-
export const parseTag = (tags: Tags | undefined, context: ActionContext): Array<TagDomain> => {
3+
export const parseTag = (tags: Tags | undefined): Array<TagDomain> => {
54
return [
65
{ key: 'iac-provider', value: 'ServerlessInsight' },
7-
...Object.entries(tags ?? {}).map(([key, value]) => ({
8-
key: replaceReference(key, context),
9-
value: replaceReference(value, context),
10-
})),
6+
...Object.entries(tags ?? {}).map(([key, value]) => ({ key, value })),
117
];
128
};

src/stack/deploy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as ros from '@alicloud/ros-cdk-core';
22
import { ActionContext, ServerlessIac } from '../types';
33
import { logger, rosStackDeploy } from '../common';
4-
import { IacStack } from './iacStack';
4+
import { RosStack } from './rosStack/rosStack';
55

66
export const generateStackTemplate = (
77
stackName: string,
88
iac: ServerlessIac,
99
context: ActionContext,
1010
) => {
1111
const app = new ros.App();
12-
new IacStack(app, iac, context);
12+
new RosStack(app, iac, context);
1313

1414
const assembly = app.synth();
1515
const stackArtifact = assembly.getStackByName(stackName);

src/stack/iacStack.ts

Lines changed: 0 additions & 255 deletions
This file was deleted.

src/stack/rosStack/database.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import * as ros from '@alicloud/ros-cdk-core';
2+
import { replaceReference } from '../../common';
3+
import { ActionContext, DatabaseDomain, DatabaseEngineMode, DatabaseEnum } from '../../types';
4+
import { isEmpty } from 'lodash';
5+
import * as esServerless from '@alicloud/ros-cdk-elasticsearchserverless';
6+
7+
export const resolveDatabases = (
8+
scope: ros.Construct,
9+
databases: Array<DatabaseDomain> | undefined,
10+
context: ActionContext,
11+
) => {
12+
if (isEmpty(databases)) {
13+
return undefined;
14+
}
15+
databases!.forEach((db) => {
16+
if ([DatabaseEnum.ELASTICSEARCH_SERVERLESS].includes(db.type)) {
17+
new esServerless.App(
18+
scope,
19+
replaceReference(db.key, context),
20+
{
21+
appName: replaceReference(db.name, context),
22+
appVersion: db.version,
23+
authentication: {
24+
basicAuth: [
25+
{
26+
password: replaceReference(db.security.basicAuth.password, context),
27+
},
28+
],
29+
},
30+
quotaInfo: {
31+
cu: db.cu,
32+
storage: db.storageSize,
33+
appType: db.engineMode === DatabaseEngineMode.TIMESERIES ? 'TRIAL' : 'STANDARD',
34+
},
35+
// network: [
36+
// {
37+
// type: 'PUBLIC_KIBANA',
38+
// enabled: true,
39+
// whiteIpGroup: [{ groupName: 'default', ips: ['0.0.0.0/24'] }],
40+
// },
41+
// {
42+
// type: 'PUBLIC_ES',
43+
// enabled: true,
44+
// whiteIpGroup: [{ groupName: 'default', ips: ['0.0.0.0/24'] }],
45+
// },
46+
// ],
47+
},
48+
true,
49+
);
50+
}
51+
});
52+
};

0 commit comments

Comments
 (0)