diff --git a/packages/@aws-cdk/core/lib/cfn-codedeploy-blue-green-hook.ts b/packages/@aws-cdk/core/lib/cfn-codedeploy-blue-green-hook.ts index c7a846fab168f..67f1b1b489fc5 100644 --- a/packages/@aws-cdk/core/lib/cfn-codedeploy-blue-green-hook.ts +++ b/packages/@aws-cdk/core/lib/cfn-codedeploy-blue-green-hook.ts @@ -302,39 +302,7 @@ export class CfnCodeDeployBlueGreenHook extends CfnHook { const hookProperties = options.parser.parseValue(hookAttributes.Properties); return new CfnCodeDeployBlueGreenHook(scope, id, { serviceRole: hookProperties?.ServiceRole, - applications: (hookProperties?.Applications ?? []).map((app: any) => { - const target = findResource(app?.Target?.LogicalID); - const taskDefinitions: Array | undefined = app?.ECSAttributes?.TaskDefinitions?.map( - (td: any) => findResource(td)); - const taskSets: Array | undefined = app?.ECSAttributes?.TaskSets?.map( - (ts: any) => findResource(ts)); - const prodTrafficRoute = findResource(app?.ECSAttributes?.TrafficRouting?.ProdTrafficRoute?.LogicalID); - const testTrafficRoute = findResource(app?.ECSAttributes?.TrafficRouting?.TestTrafficRoute?.LogicalID); - const targetGroups: Array | undefined = app?.ECSAttributes?.TrafficRouting?.TargetGroups?.map( - (tg: any) => findResource(tg)); - - return { - target: { - type: app?.Target?.Type, - logicalId: target?.logicalId, - }, - ecsAttributes: { - taskDefinitions: taskDefinitions?.map(td => td?.logicalId), - taskSets: taskSets?.map(ts => ts?.logicalId), - trafficRouting: { - prodTrafficRoute: { - type: app?.ECSAttributes?.TrafficRouting?.ProdTrafficRoute?.Type, - logicalId: prodTrafficRoute?.logicalId, - }, - testTrafficRoute: { - type: app?.ECSAttributes?.TrafficRouting?.TestTrafficRoute?.Type, - logicalId: testTrafficRoute?.logicalId, - }, - targetGroups: targetGroups?.map((tg) => tg?.logicalId), - }, - }, - }; - }), + applications: hookProperties?.Applications?.map(applicationFromCloudFormation), trafficRoutingConfig: { type: hookProperties?.TrafficRoutingConfig?.Type, timeBasedCanary: { @@ -358,6 +326,40 @@ export class CfnCodeDeployBlueGreenHook extends CfnHook { }, }); + function applicationFromCloudFormation(app: any) { + const target = findResource(app?.Target?.LogicalID); + const taskDefinitions: Array | undefined = app?.ECSAttributes?.TaskDefinitions?.map( + (td: any) => findResource(td)); + const taskSets: Array | undefined = app?.ECSAttributes?.TaskSets?.map( + (ts: any) => findResource(ts)); + const prodTrafficRoute = findResource(app?.ECSAttributes?.TrafficRouting?.ProdTrafficRoute?.LogicalID); + const testTrafficRoute = findResource(app?.ECSAttributes?.TrafficRouting?.TestTrafficRoute?.LogicalID); + const targetGroups: Array | undefined = app?.ECSAttributes?.TrafficRouting?.TargetGroups?.map( + (tg: any) => findResource(tg)); + + return { + target: { + type: app?.Target?.Type, + logicalId: target?.logicalId, + }, + ecsAttributes: { + taskDefinitions: taskDefinitions?.map(td => td?.logicalId), + taskSets: taskSets?.map(ts => ts?.logicalId), + trafficRouting: { + prodTrafficRoute: { + type: app?.ECSAttributes?.TrafficRouting?.ProdTrafficRoute?.Type, + logicalId: prodTrafficRoute?.logicalId, + }, + testTrafficRoute: { + type: app?.ECSAttributes?.TrafficRouting?.TestTrafficRoute?.Type, + logicalId: testTrafficRoute?.logicalId, + }, + targetGroups: targetGroups?.map((tg) => tg?.logicalId), + }, + }, + }; + } + function findResource(logicalId: string | undefined): CfnResource | undefined { if (logicalId == null) { return undefined;