Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support adding tags for alarms #6

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
comment: false

coverage:
status:
patch: off
project:
default:
only_pulls: true
target: auto
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface AlarmDefinition {
insufficientDataActions?: string[];
treatMissingData?: string;
metricFilter?: AlarmMetricFilterDefinition;
tags?: Record<string, string | null>;
}

// Can be string (arn) or object (!Ref/!Sub...) or an array of those
Expand Down
9 changes: 9 additions & 0 deletions src/utils/alarms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
] = {
Expand Down
1 change: 1 addition & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AlarmDefinition>;

const alarmActionSchema = z.union([
Expand Down
Loading