From 9b2d9c68b102c83d5b5e5f0e3e754fc0781234c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=91=A8=E2=80=8D=F0=9F=92=BB=20Somanshu?= Date: Fri, 2 Apr 2021 10:37:04 +0530 Subject: [PATCH] Fixed alarm rule render to support spaces in alarm name in composite alarm --- .../@aws-cdk/aws-cloudwatch/lib/alarm-base.ts | 2 +- .../test/test.composite-alarm.ts | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/alarm-base.ts b/packages/@aws-cdk/aws-cloudwatch/lib/alarm-base.ts index 996079718edba..830fa04b290e5 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/alarm-base.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/alarm-base.ts @@ -51,7 +51,7 @@ export abstract class AlarmBase extends Resource implements IAlarm { * AlarmRule indicating ALARM state for Alarm. */ public renderAlarmRule(): string { - return `ALARM(${this.alarmArn})`; + return `ALARM("${this.alarmArn}")`; } /** diff --git a/packages/@aws-cdk/aws-cloudwatch/test/test.composite-alarm.ts b/packages/@aws-cdk/aws-cloudwatch/test/test.composite-alarm.ts index 633d792f79401..6e224f2e9c025 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/test.composite-alarm.ts +++ b/packages/@aws-cdk/aws-cloudwatch/test/test.composite-alarm.ts @@ -36,12 +36,20 @@ export = { evaluationPeriods: 3, }); + const alarm5 = new Alarm(stack, 'Alarm5', { + alarmName: 'Alarm with space in name', + metric: testMetric, + threshold: 100000, + evaluationPeriods: 3, + }); + const alarmRule = AlarmRule.anyOf( AlarmRule.allOf( AlarmRule.anyOf( alarm1, AlarmRule.fromAlarm(alarm2, AlarmState.OK), alarm3, + alarm5 ), AlarmRule.not(AlarmRule.fromAlarm(alarm4, AlarmState.INSUFFICIENT_DATA)), ), @@ -58,35 +66,42 @@ export = { 'Fn::Join': [ '', [ - '(((ALARM(', + '(((ALARM("', { 'Fn::GetAtt': [ 'Alarm1F9009D71', 'Arn', ], }, - ') OR OK(', + '") OR OK("', { 'Fn::GetAtt': [ 'Alarm2A7122E13', 'Arn', ], }, - ') OR ALARM(', + '") OR ALARM("', { 'Fn::GetAtt': [ 'Alarm32341D8D9', 'Arn', ], }, - ')) AND (NOT (INSUFFICIENT_DATA(', + '") OR ALARM("', + { + 'Fn::GetAtt': [ + 'Alarm with space in name', + 'Arn', + ], + }, + '")) AND (NOT (INSUFFICIENT_DATA("', { 'Fn::GetAtt': [ 'Alarm4671832C8', 'Arn', ], }, - ')))) OR FALSE)', + '")))) OR FALSE)', ], ], },