From 097bf5e7806b36d6c9b0b5fc862a8f74facf8c9e Mon Sep 17 00:00:00 2001 From: Benura Abeywardena <43112139+BLasan@users.noreply.github.com> Date: Mon, 22 Mar 2021 16:02:26 +0530 Subject: [PATCH] fix(codedeploy): DeploymentGroup's physical name not propagated to Application (#13582) fixes #13337 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../lib/server/deployment-group.ts | 4 +++- .../test/server/test.deployment-group.ts | 21 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts index ce93f699537c7..2babdecf478be 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts @@ -269,7 +269,9 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase { physicalName: props.deploymentGroupName, }); - this.application = props.application || new ServerApplication(this, 'Application'); + this.application = props.application || new ServerApplication(this, 'Application', { + applicationName: props.deploymentGroupName === cdk.PhysicalName.GENERATE_IF_NEEDED ? cdk.PhysicalName.GENERATE_IF_NEEDED : undefined, + }); this.role = props.role || new iam.Role(this, 'Role', { assumedBy: new iam.ServicePrincipal('codedeploy.amazonaws.com'), diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/test.deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/test/server/test.deployment-group.ts index 8d2dbe44cd604..6aa102e97da11 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/test.deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/test/server/test.deployment-group.ts @@ -1,4 +1,4 @@ -import { expect, haveResource, SynthUtils } from '@aws-cdk/assert'; +import { expect, haveOutput, haveResource, SynthUtils } from '@aws-cdk/assert'; import * as autoscaling from '@aws-cdk/aws-autoscaling'; import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; import * as ec2 from '@aws-cdk/aws-ec2'; @@ -28,6 +28,25 @@ export = { test.done(); }, + 'creating an application with physical name if needed'(test: Test) { + const stack = new cdk.Stack(undefined, undefined, { env: { account: '12345', region: 'us-test-1' } }); + const stack2 = new cdk.Stack(undefined, undefined, { env: { account: '12346', region: 'us-test-2' } }); + const serverDeploymentGroup = new codedeploy.ServerDeploymentGroup(stack, 'MyDG', { + deploymentGroupName: cdk.PhysicalName.GENERATE_IF_NEEDED, + }); + + new cdk.CfnOutput(stack2, 'Output', { + value: serverDeploymentGroup.application.applicationName, + }); + + expect(stack2).to(haveOutput({ + outputName: 'Output', + outputValue: 'defaultmydgapplication78dba0bb0c7580b32033', + })); + + test.done(); + }, + 'can be imported'(test: Test) { const stack = new cdk.Stack();