From 1aea938ee0d63f7b6e26bb70600d83eb9b5a236e Mon Sep 17 00:00:00 2001 From: Jane Chen Date: Thu, 21 Sep 2023 16:16:44 -0400 Subject: [PATCH 1/2] fix(appconfig): allow multiple environment monitor roles to be created --- .../aws-appconfig-alpha/lib/environment.ts | 8 +- .../test/environment.test.ts | 76 ++++++++++++++++++- ...efaultTestDeployAssert75BD28E7.assets.json | 2 +- .../aws-appconfig-environment.assets.json | 6 +- .../aws-appconfig-environment.template.json | 4 +- .../integ.environment.js.snapshot/cdk.out | 2 +- .../integ.environment.js.snapshot/integ.json | 2 +- .../manifest.json | 8 +- .../integ.environment.js.snapshot/tree.json | 24 +++--- 9 files changed, 103 insertions(+), 29 deletions(-) diff --git a/packages/@aws-cdk/aws-appconfig-alpha/lib/environment.ts b/packages/@aws-cdk/aws-appconfig-alpha/lib/environment.ts index cd59cfa4265a5..fdcd7a29d92b6 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/lib/environment.ts +++ b/packages/@aws-cdk/aws-appconfig-alpha/lib/environment.ts @@ -236,10 +236,10 @@ export class Environment extends EnvironmentBase { applicationId: this.applicationId, name: this.name, description: this.description, - monitors: this.monitors?.map((monitor) => { + monitors: this.monitors?.map((monitor, index) => { return { alarmArn: monitor.alarm.alarmArn, - alarmRoleArn: monitor.alarmRole?.roleArn || this.createAlarmRole(monitor.alarm.alarmArn).roleArn, + alarmRoleArn: monitor.alarmRole?.roleArn || this.createAlarmRole(monitor.alarm.alarmArn, index).roleArn, }; }), }); @@ -256,7 +256,7 @@ export class Environment extends EnvironmentBase { this.application.addExistingEnvironment(this); } - private createAlarmRole(alarmArn: string): iam.IRole { + private createAlarmRole(alarmArn: string, index: number): iam.IRole { const policy = new iam.PolicyStatement({ effect: iam.Effect.ALLOW, actions: ['cloudwatch:DescribeAlarms'], @@ -265,7 +265,7 @@ export class Environment extends EnvironmentBase { const document = new iam.PolicyDocument({ statements: [policy], }); - const role = new iam.Role(this, 'Role', { + const role = new iam.Role(this, `Role${index}`, { roleName: PhysicalName.GENERATE_IF_NEEDED, assumedBy: new iam.ServicePrincipal('appconfig.amazonaws.com'), inlinePolicies: { diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/environment.test.ts b/packages/@aws-cdk/aws-appconfig-alpha/test/environment.test.ts index e0950fa0ed564..ffb8c092fa820 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/environment.test.ts +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/environment.test.ts @@ -147,7 +147,7 @@ describe('environment', () => { }, AlarmRoleArn: { 'Fn::GetAtt': [ - 'MyEnvironmentRoleC08961D3', + 'MyEnvironmentRole01C8C013F', 'Arn', ], }, @@ -177,6 +177,80 @@ describe('environment', () => { }); }); + test('environment with monitors with two alarms', () => { + const stack = new cdk.Stack(); + const app = new Application(stack, 'MyAppConfig'); + new Environment(stack, 'MyEnvironment', { + name: 'TestEnv', + application: app, + monitors: [ + { + alarm: new Alarm(stack, 'Alarm1', { + threshold: 5, + evaluationPeriods: 5, + metric: new Metric( + { + namespace: 'aws', + metricName: 'myMetric', + }, + ), + }), + }, + { + alarm: new Alarm(stack, 'Alarm2', { + threshold: 5, + evaluationPeriods: 5, + metric: new Metric( + { + namespace: 'aws', + metricName: 'myMetric', + }, + ), + }), + }, + ], + }); + + Template.fromStack(stack).resourceCountIs('AWS::CloudWatch::Alarm', 2); + Template.fromStack(stack).resourceCountIs('AWS::IAM::Role', 2); + Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::Environment', { + Name: 'TestEnv', + ApplicationId: { + Ref: 'MyAppConfigB4B63E75', + }, + Monitors: [ + { + AlarmArn: { + 'Fn::GetAtt': [ + 'Alarm1F9009D71', + 'Arn', + ], + }, + AlarmRoleArn: { + 'Fn::GetAtt': [ + 'MyEnvironmentRole01C8C013F', + 'Arn', + ], + }, + }, + { + AlarmArn: { + 'Fn::GetAtt': [ + 'Alarm2A7122E13', + 'Arn', + ], + }, + AlarmRoleArn: { + 'Fn::GetAtt': [ + 'MyEnvironmentRole135A2CEE4', + 'Arn', + ], + }, + }, + ], + }); + }); + test('from environment arn', () => { const stack = new cdk.Stack(); const env = Environment.fromEnvironmentArn(stack, 'MyEnvironment', diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/appconfigenvironmentDefaultTestDeployAssert75BD28E7.assets.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/appconfigenvironmentDefaultTestDeployAssert75BD28E7.assets.json index e7f9aca08607f..49f0e48e091a4 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/appconfigenvironmentDefaultTestDeployAssert75BD28E7.assets.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/appconfigenvironmentDefaultTestDeployAssert75BD28E7.assets.json @@ -1,5 +1,5 @@ { - "version": "32.0.0", + "version": "34.0.0", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.assets.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.assets.json index 30512d7b22c0b..eaecc5a6b3377 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.assets.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.assets.json @@ -1,7 +1,7 @@ { - "version": "32.0.0", + "version": "34.0.0", "files": { - "5a83c94c795349286c703ba61add79efe69c74c7adb8de98527fcf034b9683af": { + "610cbf4701a1d09b46d0f5dcddb700815ab9758d826bae0d0a0435cefc679345": { "source": { "path": "aws-appconfig-environment.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "5a83c94c795349286c703ba61add79efe69c74c7adb8de98527fcf034b9683af.json", + "objectKey": "610cbf4701a1d09b46d0f5dcddb700815ab9758d826bae0d0a0435cefc679345.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.template.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.template.json index 78b08f894831d..7ecc7cc820aaa 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.template.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.template.json @@ -18,7 +18,7 @@ "Threshold": 10 } }, - "MyEnvironmentRoleC08961D3": { + "MyEnvironmentRole2EA31107E16C4": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -72,7 +72,7 @@ }, "AlarmRoleArn": { "Fn::GetAtt": [ - "MyEnvironmentRoleC08961D3", + "MyEnvironmentRole2EA31107E16C4", "Arn" ] } diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/cdk.out b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/cdk.out index f0b901e7c06e5..2313ab5436501 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"32.0.0"} \ No newline at end of file +{"version":"34.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/integ.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/integ.json index 4d4d0f1d20168..a9ffb18c9ba71 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "32.0.0", + "version": "34.0.0", "testCases": { "appconfig-environment/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/manifest.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/manifest.json index 0749986d2339c..139bf660f1799 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "32.0.0", + "version": "34.0.0", "artifacts": { "aws-appconfig-environment.assets": { "type": "cdk:asset-manifest", @@ -17,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5a83c94c795349286c703ba61add79efe69c74c7adb8de98527fcf034b9683af.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/610cbf4701a1d09b46d0f5dcddb700815ab9758d826bae0d0a0435cefc679345.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -45,10 +45,10 @@ "data": "MyAlarm696658B6" } ], - "/aws-appconfig-environment/MyEnvironment/Role/Resource": [ + "/aws-appconfig-environment/MyEnvironment/Role2EA31/Resource": [ { "type": "aws:cdk:logicalId", - "data": "MyEnvironmentRoleC08961D3" + "data": "MyEnvironmentRole2EA31107E16C4" } ], "/aws-appconfig-environment/MyEnvironment/Resource": [ diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/tree.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/tree.json index f094a53e8edb1..f35cdec885d76 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/tree.json @@ -28,7 +28,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-appconfig-alpha.Application", "version": "0.0.0" } }, @@ -66,13 +66,13 @@ "id": "MyEnvironment", "path": "aws-appconfig-environment/MyEnvironment", "children": { - "Role": { - "id": "Role", - "path": "aws-appconfig-environment/MyEnvironment/Role", + "Role2EA31": { + "id": "Role2EA31", + "path": "aws-appconfig-environment/MyEnvironment/Role2EA31", "children": { - "ImportRole": { - "id": "ImportRole", - "path": "aws-appconfig-environment/MyEnvironment/Role/ImportRole", + "ImportRole2EA31": { + "id": "ImportRole2EA31", + "path": "aws-appconfig-environment/MyEnvironment/Role2EA31/ImportRole2EA31", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -80,7 +80,7 @@ }, "Resource": { "id": "Resource", - "path": "aws-appconfig-environment/MyEnvironment/Role/Resource", + "path": "aws-appconfig-environment/MyEnvironment/Role2EA31/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::Role", "aws:cdk:cloudformation:props": { @@ -149,7 +149,7 @@ }, "alarmRoleArn": { "Fn::GetAtt": [ - "MyEnvironmentRoleC08961D3", + "MyEnvironmentRole2EA31107E16C4", "Arn" ] } @@ -165,7 +165,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-appconfig-alpha.Environment", "version": "0.0.0" } }, @@ -204,7 +204,7 @@ "path": "appconfig-environment/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.69" + "version": "10.2.70" } }, "DeployAssert": { @@ -250,7 +250,7 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.69" + "version": "10.2.70" } } }, From ea90892790742df4ca96d3da0436f9d8df8f8d45 Mon Sep 17 00:00:00 2001 From: Jane Chen Date: Tue, 26 Sep 2023 10:20:15 -0400 Subject: [PATCH 2/2] Add new integ test snapshots --- .../aws-appconfig-environment.assets.json | 4 ++-- .../aws-appconfig-environment.template.json | 4 ++-- .../integ.environment.js.snapshot/manifest.json | 6 +++--- .../test/integ.environment.js.snapshot/tree.json | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.assets.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.assets.json index eaecc5a6b3377..8a91333b6e2d2 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.assets.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.assets.json @@ -1,7 +1,7 @@ { "version": "34.0.0", "files": { - "610cbf4701a1d09b46d0f5dcddb700815ab9758d826bae0d0a0435cefc679345": { + "c5abc7ef2e341477218fc19664c82ee2ea13e9509f2deaae6fc6200a619a5d1c": { "source": { "path": "aws-appconfig-environment.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "610cbf4701a1d09b46d0f5dcddb700815ab9758d826bae0d0a0435cefc679345.json", + "objectKey": "c5abc7ef2e341477218fc19664c82ee2ea13e9509f2deaae6fc6200a619a5d1c.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.template.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.template.json index 7ecc7cc820aaa..e120019dcabe1 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.template.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/aws-appconfig-environment.template.json @@ -18,7 +18,7 @@ "Threshold": 10 } }, - "MyEnvironmentRole2EA31107E16C4": { + "MyEnvironmentRole01C8C013F": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -72,7 +72,7 @@ }, "AlarmRoleArn": { "Fn::GetAtt": [ - "MyEnvironmentRole2EA31107E16C4", + "MyEnvironmentRole01C8C013F", "Arn" ] } diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/manifest.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/manifest.json index 139bf660f1799..6f758fc4db657 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/manifest.json @@ -17,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/610cbf4701a1d09b46d0f5dcddb700815ab9758d826bae0d0a0435cefc679345.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c5abc7ef2e341477218fc19664c82ee2ea13e9509f2deaae6fc6200a619a5d1c.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -45,10 +45,10 @@ "data": "MyAlarm696658B6" } ], - "/aws-appconfig-environment/MyEnvironment/Role2EA31/Resource": [ + "/aws-appconfig-environment/MyEnvironment/Role0/Resource": [ { "type": "aws:cdk:logicalId", - "data": "MyEnvironmentRole2EA31107E16C4" + "data": "MyEnvironmentRole01C8C013F" } ], "/aws-appconfig-environment/MyEnvironment/Resource": [ diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/tree.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/tree.json index f35cdec885d76..730c4e7fb0302 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.environment.js.snapshot/tree.json @@ -66,13 +66,13 @@ "id": "MyEnvironment", "path": "aws-appconfig-environment/MyEnvironment", "children": { - "Role2EA31": { - "id": "Role2EA31", - "path": "aws-appconfig-environment/MyEnvironment/Role2EA31", + "Role0": { + "id": "Role0", + "path": "aws-appconfig-environment/MyEnvironment/Role0", "children": { - "ImportRole2EA31": { - "id": "ImportRole2EA31", - "path": "aws-appconfig-environment/MyEnvironment/Role2EA31/ImportRole2EA31", + "ImportRole0": { + "id": "ImportRole0", + "path": "aws-appconfig-environment/MyEnvironment/Role0/ImportRole0", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -80,7 +80,7 @@ }, "Resource": { "id": "Resource", - "path": "aws-appconfig-environment/MyEnvironment/Role2EA31/Resource", + "path": "aws-appconfig-environment/MyEnvironment/Role0/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::Role", "aws:cdk:cloudformation:props": { @@ -149,7 +149,7 @@ }, "alarmRoleArn": { "Fn::GetAtt": [ - "MyEnvironmentRole2EA31107E16C4", + "MyEnvironmentRole01C8C013F", "Arn" ] }