From 3965d8b84dcfa3ed32c02275b12baf162c871003 Mon Sep 17 00:00:00 2001 From: LironEr Date: Wed, 17 Apr 2024 00:04:30 +0300 Subject: [PATCH] feat!: support adding tags for alarms --- README.md | 2 ++ codecov.yml | 9 +++++++++ src/types.ts | 1 + src/utils/alarms.ts | 9 +++++++++ src/utils/config.ts | 1 + 5 files changed, 22 insertions(+) create mode 100644 codecov.yml diff --git a/README.md b/README.md index 18a02cc..4ce71b8 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ custom: nameTemplate: $[functionName]-$[metricName]-alarm # Optional - naming template for alarms, can be overwritten in definitions prefixTemplate: $[stackName] # Optional - override the alarm name prefix suffixTemplate: alarm # Optional - override the alarm name suffix + tags: + TEAM: my-team definitions: # these defaults are merged with your definitions lambdaErrors: diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..fea1c92 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,9 @@ +comment: false + +coverage: + status: + patch: off + project: + default: + only_pulls: true + target: auto diff --git a/src/types.ts b/src/types.ts index 86b5af9..86ff682 100644 --- a/src/types.ts +++ b/src/types.ts @@ -29,6 +29,7 @@ export interface AlarmDefinition { insufficientDataActions?: string[]; treatMissingData?: string; metricFilter?: AlarmMetricFilterDefinition; + tags?: Record; } // Can be string (arn) or object (!Ref/!Sub...) or an array of those diff --git a/src/utils/alarms.ts b/src/utils/alarms.ts index 1dcc15d..5d017a8 100644 --- a/src/utils/alarms.ts +++ b/src/utils/alarms.ts @@ -94,6 +94,15 @@ export function generateCloudFormationResourcesForDefinition( TreatMissingData: alarm.treatMissingData, }; + if (alarm.tags && Object.keys(alarm.tags).length > 0) { + cfAlarmProperties.Tags = Object.entries(alarm.tags) + .map(([key, value]) => ({ + Key: key, + Value: value, + })) + .filter((tag) => !!tag.Value); + } + resources[ awsNaming.getNormalizedResourceName(`${lambdaLogicalId}${awsNaming.normalizeName(alarmDefinitionName)}Alarm`) ] = { diff --git a/src/utils/config.ts b/src/utils/config.ts index 6d755a6..b279557 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -44,6 +44,7 @@ const alarmDefSchema = z.object({ insufficientDataActions: z.array(z.string()).optional(), treatMissingData: z.optional(z.enum(['missing', 'ignore', 'breaching', 'notBreaching'])), metricFilter: z.optional(alarmMetricFilterDefSchema), + tags: z.optional(z.record(z.string().min(1).max(128), z.string().min(1).max(256).nullable())), }) satisfies z.ZodType; const alarmActionSchema = z.union([