Skip to content

Commit 93d178e

Browse files
committed
feat: add tags to defined resources
Signed-off-by: seven <zilisheng1996@gmail.com>
1 parent 8b92af3 commit 93d178e

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/iac/parse.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const mapToArr = (obj: Record<string, Record<string, unknown> | string>) => {
99
);
1010
};
1111

12+
const mapToKvArr = (obj: Record<string, string>) => {
13+
return Object.entries(obj).map(([key, value]) => ({ key, value }));
14+
};
15+
1216
const validateExistence = (path: string) => {
1317
if (!existsSync(path)) {
1418
throw new Error(`File does not exist at path: ${path}`);
@@ -24,7 +28,10 @@ const transformYaml = (iacJson: RawServerlessIac): ServerlessIac => {
2428
stages: iacJson.stages,
2529
functions: mapToArr(iacJson.functions) as unknown as Array<IacFunction>,
2630
events: mapToArr(iacJson.events) as unknown as Array<Event>,
27-
tags: mapToArr(iacJson.tags) as unknown as Array<string>,
31+
tags: [
32+
{ key: 'iac-provider', value: 'ServerlessInsight' },
33+
...mapToKvArr(iacJson.tags),
34+
] as unknown as Array<{ key: string; value: string }>,
2835
};
2936
};
3037

src/stack/deploy.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ const resolveCode = (location: string): string => {
1717

1818
export class IacStack extends ros.Stack {
1919
constructor(scope: ros.Construct, iac: ServerlessIac, context: ActionContext) {
20-
super(scope, iac.service);
20+
super(scope, iac.service, {
21+
tags: iac.tags.reduce((acc: { [key: string]: string }, tag) => {
22+
acc[tag.key] = tag.value;
23+
return acc;
24+
}, {}),
25+
});
26+
console.log('tags', iac.tags);
2127
new ros.RosInfo(this, ros.RosInfo.description, `${iac.service} stack`);
2228

2329
const service = new fc.RosService(
2430
this,
2531
`${iac.service}-service`,
2632
{
2733
serviceName: `${iac.service}-service`,
34+
tags: iac.tags,
2835
},
2936
true,
3037
);
@@ -95,6 +102,7 @@ export class IacStack extends ros.Stack {
95102
`${iac.service}_apigroup`,
96103
{
97104
groupName: `${iac.service}_apigroup`,
105+
tags: iac.tags,
98106
},
99107
true,
100108
);
@@ -128,6 +136,7 @@ export class IacStack extends ros.Stack {
128136
},
129137
resultSample: 'ServerlessInsight resultSample',
130138
resultType: 'JSON',
139+
tags: iac.tags,
131140
},
132141
true,
133142
);

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export type ServerlessIac = {
6363
vars: Vars;
6464
stages: Stages;
6565
service: string;
66-
tags: Array<string>;
66+
tags: Array<{ key: string; value: string }>;
6767
functions: Array<IacFunction>;
6868
events: Array<Event>;
6969
};

0 commit comments

Comments
 (0)