Skip to content

Commit

Permalink
feat: add tags to defined resources
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Sep 22, 2024
1 parent 8b92af3 commit 93d178e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/iac/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const mapToArr = (obj: Record<string, Record<string, unknown> | string>) => {
);
};

const mapToKvArr = (obj: Record<string, string>) => {
return Object.entries(obj).map(([key, value]) => ({ key, value }));
};

const validateExistence = (path: string) => {
if (!existsSync(path)) {
throw new Error(`File does not exist at path: ${path}`);
Expand All @@ -24,7 +28,10 @@ const transformYaml = (iacJson: RawServerlessIac): ServerlessIac => {
stages: iacJson.stages,
functions: mapToArr(iacJson.functions) as unknown as Array<IacFunction>,
events: mapToArr(iacJson.events) as unknown as Array<Event>,
tags: mapToArr(iacJson.tags) as unknown as Array<string>,
tags: [
{ key: 'iac-provider', value: 'ServerlessInsight' },
...mapToKvArr(iacJson.tags),
] as unknown as Array<{ key: string; value: string }>,
};
};

Expand Down
11 changes: 10 additions & 1 deletion src/stack/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ const resolveCode = (location: string): string => {

export class IacStack extends ros.Stack {
constructor(scope: ros.Construct, iac: ServerlessIac, context: ActionContext) {
super(scope, iac.service);
super(scope, iac.service, {
tags: iac.tags.reduce((acc: { [key: string]: string }, tag) => {
acc[tag.key] = tag.value;
return acc;
}, {}),
});
console.log('tags', iac.tags);
new ros.RosInfo(this, ros.RosInfo.description, `${iac.service} stack`);

const service = new fc.RosService(
this,
`${iac.service}-service`,
{
serviceName: `${iac.service}-service`,
tags: iac.tags,
},
true,
);
Expand Down Expand Up @@ -95,6 +102,7 @@ export class IacStack extends ros.Stack {
`${iac.service}_apigroup`,
{
groupName: `${iac.service}_apigroup`,
tags: iac.tags,
},
true,
);
Expand Down Expand Up @@ -128,6 +136,7 @@ export class IacStack extends ros.Stack {
},
resultSample: 'ServerlessInsight resultSample',
resultType: 'JSON',
tags: iac.tags,
},
true,
);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type ServerlessIac = {
vars: Vars;
stages: Stages;
service: string;
tags: Array<string>;
tags: Array<{ key: string; value: string }>;
functions: Array<IacFunction>;
events: Array<Event>;
};
Expand Down

0 comments on commit 93d178e

Please sign in to comment.