From ad62333f0a35b4c92b3c9ee4789551b1a34a1417 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Wed, 15 May 2019 07:07:34 -0700 Subject: [PATCH] fix(codedeploy): change the load balancer API in server Deployment Group. BREAKING CHANGE: the type of the `loadBalancer` property in ServerDeploymentGroupProps has been changed. Fixes #2449 --- .../@aws-cdk/aws-codedeploy-api/README.md | 8 +- .../@aws-cdk/aws-codedeploy-api/lib/index.ts | 1 - .../aws-codedeploy-api/lib/load-balancer.ts | 32 ------- .../@aws-cdk/aws-codedeploy-api/package.json | 1 + packages/@aws-cdk/aws-codedeploy/README.md | 16 ++-- .../lib/server/deployment-group.ts | 22 +++-- .../aws-codedeploy/lib/server/index.ts | 1 + .../lib/server/load-balancer.ts | 90 +++++++++++++++++++ packages/@aws-cdk/aws-codedeploy/package.json | 8 +- .../test/server/integ.deployment-group.ts | 2 +- .../test/server/test.deployment-group.ts | 4 +- .../lib/load-balancer.ts | 10 +-- .../aws-elasticloadbalancing/package.json | 2 - .../lib/shared/base-target-group.ts | 10 +-- .../package-lock.json | 7 +- .../aws-elasticloadbalancingv2/package.json | 2 - packages/decdk/package.json | 3 +- 17 files changed, 125 insertions(+), 94 deletions(-) delete mode 100644 packages/@aws-cdk/aws-codedeploy-api/lib/load-balancer.ts create mode 100644 packages/@aws-cdk/aws-codedeploy/lib/server/load-balancer.ts diff --git a/packages/@aws-cdk/aws-codedeploy-api/README.md b/packages/@aws-cdk/aws-codedeploy-api/README.md index 231f860239c9a..bb1edb95bb0ff 100644 --- a/packages/@aws-cdk/aws-codedeploy-api/README.md +++ b/packages/@aws-cdk/aws-codedeploy-api/README.md @@ -1,7 +1,5 @@ ## AWS CodeDeploy Load Balancing API -This package contains the abstract API of Load Balancers -as required by the AWS CodeDeploy Construct Library. - -You should never need to depend on it directly - -instead, depend on the `aws-codedeploy` package. +This package has been deprecated, +and will be removed in a future release of the Cloud Development Kit. +Please remove if from your dependencies. diff --git a/packages/@aws-cdk/aws-codedeploy-api/lib/index.ts b/packages/@aws-cdk/aws-codedeploy-api/lib/index.ts index c125cdad8aa0e..e69de29bb2d1d 100644 --- a/packages/@aws-cdk/aws-codedeploy-api/lib/index.ts +++ b/packages/@aws-cdk/aws-codedeploy-api/lib/index.ts @@ -1 +0,0 @@ -export * from './load-balancer'; diff --git a/packages/@aws-cdk/aws-codedeploy-api/lib/load-balancer.ts b/packages/@aws-cdk/aws-codedeploy-api/lib/load-balancer.ts deleted file mode 100644 index 32b9218e438e1..0000000000000 --- a/packages/@aws-cdk/aws-codedeploy-api/lib/load-balancer.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * The generations of AWS load balancing solutions. - */ -export enum LoadBalancerGeneration { - /** - * The first generation (ELB Classic). - */ - First, - - /** - * The second generation (ALB and NLB). - */ - Second -} - -/** - * The properties CodeDeploy requires of a load balancer. - */ -export interface ILoadBalancerProps { - generation: LoadBalancerGeneration; - name: string; -} - -/** - * An interface of an abstract laod balancer, as needed by CodeDeploy. - */ -export interface ILoadBalancer { - /** - * Specify the CodeDeploy-required properties of this load balancer. - */ - asCodeDeployLoadBalancer(): ILoadBalancerProps; -} diff --git a/packages/@aws-cdk/aws-codedeploy-api/package.json b/packages/@aws-cdk/aws-codedeploy-api/package.json index 2deb47689b29d..4e74ac8e251b7 100644 --- a/packages/@aws-cdk/aws-codedeploy-api/package.json +++ b/packages/@aws-cdk/aws-codedeploy-api/package.json @@ -2,6 +2,7 @@ "name": "@aws-cdk/aws-codedeploy-api", "version": "0.31.0", "description": "Load Balancer API for AWS CodeDeploy", + "deprecated": "This package is now obsololete, please remove it from your dependencies", "main": "lib/index.js", "types": "lib/index.d.ts", "jsii": { diff --git a/packages/@aws-cdk/aws-codedeploy/README.md b/packages/@aws-cdk/aws-codedeploy/README.md index 5e8d3b9aa74be..3865ef849430e 100644 --- a/packages/@aws-cdk/aws-codedeploy/README.md +++ b/packages/@aws-cdk/aws-codedeploy/README.md @@ -90,21 +90,23 @@ const deploymentGroup = codedeploy.ServerDeploymentGroup.import(this, 'ExistingC You can [specify a load balancer](https://docs.aws.amazon.com/codedeploy/latest/userguide/integrations-aws-elastic-load-balancing.html) with the `loadBalancer` property when creating a Deployment Group. +`LoadBalancer` is an abstract class with static factory methods that allow you to create instances of it from various sources. + With Classic Elastic Load Balancer, you provide it directly: ```ts import lb = require('@aws-cdk/aws-elasticloadbalancing'); const elb = new lb.LoadBalancer(this, 'ELB', { - // ... + // ... }); elb.addTarget(/* ... */); elb.addListener({ - // ... + // ... }); const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'DeploymentGroup', { - loadBalancer: elb, + loadBalancer: codedeploy.LoadBalancer.classic(elb), }); ``` @@ -115,17 +117,17 @@ you provide a Target Group as the load balancer: import lbv2 = require('@aws-cdk/aws-elasticloadbalancingv2'); const alb = new lbv2.ApplicationLoadBalancer(this, 'ALB', { - // ... + // ... }); const listener = alb.addListener('Listener', { - // ... + // ... }); const targetGroup = listener.addTargets('Fleet', { - // ... + // ... }); const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'DeploymentGroup', { - loadBalancer: targetGroup, + loadBalancer: codedeploy.LoadBalancer.application(targetGroup), }); ``` 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 e90aa98ef4b13..643b45b6c5983 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts @@ -1,6 +1,5 @@ import autoscaling = require('@aws-cdk/aws-autoscaling'); import cloudwatch = require('@aws-cdk/aws-cloudwatch'); -import codedeploylb = require('@aws-cdk/aws-codedeploy-api'); import ec2 = require('@aws-cdk/aws-ec2'); import iam = require('@aws-cdk/aws-iam'); import s3 = require('@aws-cdk/aws-s3'); @@ -10,6 +9,7 @@ import { AutoRollbackConfig } from '../rollback-config'; import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../utils'; import { IServerApplication, ServerApplication } from './application'; import { IServerDeploymentConfig, ServerDeploymentConfig } from './deployment-config'; +import { LoadBalancer, LoadBalancerGeneration } from './load-balancer'; export interface IServerDeploymentGroup extends cdk.IResource { readonly application: IServerApplication; @@ -190,12 +190,12 @@ export interface ServerDeploymentGroupProps { /** * The load balancer to place in front of this Deployment Group. - * Can be either a classic Elastic Load Balancer, + * Can be created from either a classic Elastic Load Balancer, * or an Application Load Balancer / Network Load Balancer Target Group. * * @default the Deployment Group will not have a load balancer defined */ - readonly loadBalancer?: codedeploylb.ILoadBalancer; + readonly loadBalancer?: LoadBalancer; /** * All EC2 instances matching the given set of tags when a deployment occurs will be added to this Deployment Group. @@ -387,25 +387,23 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase { } } - private loadBalancerInfo(lbProvider?: codedeploylb.ILoadBalancer): + private loadBalancerInfo(loadBalancer?: LoadBalancer): CfnDeploymentGroup.LoadBalancerInfoProperty | undefined { - if (!lbProvider) { + if (!loadBalancer) { return undefined; } - const lb = lbProvider.asCodeDeployLoadBalancer(); - - switch (lb.generation) { - case codedeploylb.LoadBalancerGeneration.First: + switch (loadBalancer.generation) { + case LoadBalancerGeneration.FIRST: return { elbInfoList: [ - { name: lb.name }, + { name: loadBalancer.name }, ], }; - case codedeploylb.LoadBalancerGeneration.Second: + case LoadBalancerGeneration.SECOND: return { targetGroupInfoList: [ - { name: lb.name }, + { name: loadBalancer.name }, ] }; } diff --git a/packages/@aws-cdk/aws-codedeploy/lib/server/index.ts b/packages/@aws-cdk/aws-codedeploy/lib/server/index.ts index 933062a88e18e..d144dd2bf472b 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/server/index.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/index.ts @@ -1,3 +1,4 @@ export * from './application'; export * from './deployment-config'; export * from './deployment-group'; +export * from './load-balancer'; diff --git a/packages/@aws-cdk/aws-codedeploy/lib/server/load-balancer.ts b/packages/@aws-cdk/aws-codedeploy/lib/server/load-balancer.ts new file mode 100644 index 0000000000000..c1cfe77e48d28 --- /dev/null +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/load-balancer.ts @@ -0,0 +1,90 @@ +import elb = require('@aws-cdk/aws-elasticloadbalancing'); +import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2'); + +/** + * The generations of AWS load balancing solutions. + */ +export enum LoadBalancerGeneration { + /** + * The first generation (ELB Classic). + */ + FIRST = 0, + + /** + * The second generation (ALB and NLB). + */ + SECOND = 1 +} + +/** + * An interface of an abstract load balancer, as needed by CodeDeploy. + * Create instances using the static factory methods: + * {@link #classic}, {@link #application} and {@link #network}. + */ +export abstract class LoadBalancer { + /** + * Creates a new CodeDeploy load balancer from a Classic ELB Load Balancer. + * + * @param loadBalancer a classic ELB Load Balancer + */ + public static classic(loadBalancer: elb.LoadBalancer): LoadBalancer { + return new ClassicLoadBalancer(loadBalancer); + } + + /** + * Creates a new CodeDeploy load balancer from an Application Load Balancer Target Group. + * + * @param albTargetGroup an ALB Target Group + */ + public static application(albTargetGroup: elbv2.ApplicationTargetGroup): LoadBalancer { + return new AlbLoadBalancer(albTargetGroup); + } + + /** + * Creates a new CodeDeploy load balancer from a Network Load Balancer Target Group. + * + * @param nlbTargetGroup an NLB Target Group + */ + public static network(nlbTargetGroup: elbv2.NetworkTargetGroup): LoadBalancer { + return new NlbLoadBalancer(nlbTargetGroup); + } + + public abstract readonly generation: LoadBalancerGeneration; + public abstract readonly name: string; +} + +class ClassicLoadBalancer extends LoadBalancer { + public readonly generation: LoadBalancerGeneration; + public readonly name: string; + + constructor(loadBalancer: elb.LoadBalancer) { + super(); + + this.generation = LoadBalancerGeneration.FIRST; + this.name = loadBalancer.loadBalancerName; + } +} + +class AlbLoadBalancer extends LoadBalancer { + public readonly generation: LoadBalancerGeneration; + public readonly name: string; + + constructor(targetGroup: elbv2.ApplicationTargetGroup) { + super(); + + this.generation = LoadBalancerGeneration.SECOND; + this.name = targetGroup.targetGroupName; + } +} + +class NlbLoadBalancer extends LoadBalancer { + public readonly generation: LoadBalancerGeneration; + public readonly name: string; + + constructor(targetGroup: elbv2.NetworkTargetGroup) { + super(); + + this.generation = LoadBalancerGeneration.SECOND; + this.name = targetGroup.targetGroupName; + } +} diff --git a/packages/@aws-cdk/aws-codedeploy/package.json b/packages/@aws-cdk/aws-codedeploy/package.json index 80515d990cf93..4d851a224d458 100644 --- a/packages/@aws-cdk/aws-codedeploy/package.json +++ b/packages/@aws-cdk/aws-codedeploy/package.json @@ -63,8 +63,6 @@ "devDependencies": { "@aws-cdk/assert": "^0.31.0", "@aws-cdk/aws-ec2": "^0.31.0", - "@aws-cdk/aws-elasticloadbalancing": "^0.31.0", - "@aws-cdk/aws-elasticloadbalancingv2": "^0.31.0", "cdk-build-tools": "^0.31.0", "cdk-integ-tools": "^0.31.0", "cfn2ts": "^0.31.0", @@ -73,7 +71,8 @@ "dependencies": { "@aws-cdk/aws-autoscaling": "^0.31.0", "@aws-cdk/aws-cloudwatch": "^0.31.0", - "@aws-cdk/aws-codedeploy-api": "^0.31.0", + "@aws-cdk/aws-elasticloadbalancing": "^0.31.0", + "@aws-cdk/aws-elasticloadbalancingv2": "^0.31.0", "@aws-cdk/aws-iam": "^0.31.0", "@aws-cdk/aws-lambda": "^0.31.0", "@aws-cdk/aws-s3": "^0.31.0", @@ -83,7 +82,8 @@ "peerDependencies": { "@aws-cdk/aws-autoscaling": "^0.31.0", "@aws-cdk/aws-cloudwatch": "^0.31.0", - "@aws-cdk/aws-codedeploy-api": "^0.31.0", + "@aws-cdk/aws-elasticloadbalancing": "^0.31.0", + "@aws-cdk/aws-elasticloadbalancingv2": "^0.31.0", "@aws-cdk/aws-iam": "^0.31.0", "@aws-cdk/aws-lambda": "^0.31.0", "@aws-cdk/aws-s3": "^0.31.0", diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.ts index 5005904f39493..b6ea00d31df5b 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.ts @@ -25,7 +25,7 @@ elb.addListener({ new codedeploy.ServerDeploymentGroup(stack, 'CodeDeployGroup', { deploymentConfig: codedeploy.ServerDeploymentConfig.AllAtOnce, autoScalingGroups: [asg], - loadBalancer: elb, + loadBalancer: codedeploy.LoadBalancer.classic(elb), alarms: [ new cloudwatch.Alarm(stack, 'Alarm1', { metric: new cloudwatch.Metric({ 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 19f3fb6094a4c..82957b3302cc2 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 @@ -101,7 +101,7 @@ export = { const targetGroup = listener.addTargets('Fleet', { protocol: lbv2.ApplicationProtocol.Http }); new codedeploy.ServerDeploymentGroup(stack, 'DeploymentGroup', { - loadBalancer: targetGroup, + loadBalancer: codedeploy.LoadBalancer.application(targetGroup), }); expect(stack).to(haveResource('AWS::CodeDeploy::DeploymentGroup', { @@ -135,7 +135,7 @@ export = { const targetGroup = listener.addTargets('Fleet', { port: 80 }); new codedeploy.ServerDeploymentGroup(stack, 'DeploymentGroup', { - loadBalancer: targetGroup, + loadBalancer: codedeploy.LoadBalancer.network(targetGroup), }); expect(stack).to(haveResource('AWS::CodeDeploy::DeploymentGroup', { diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts index 72ad94c36a209..76e164f4862a3 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts @@ -1,4 +1,3 @@ -import codedeploy = require('@aws-cdk/aws-codedeploy-api'); import { AnyIPv4, Connections, IConnectable, IPortRange, ISecurityGroup, IVpcNetwork, IVpcSubnet, SecurityGroup, TcpPort } from '@aws-cdk/aws-ec2'; @@ -188,7 +187,7 @@ export enum LoadBalancingProtocol { * * Routes to a fleet of of instances in a VPC. */ -export class LoadBalancer extends Resource implements IConnectable, codedeploy.ILoadBalancer { +export class LoadBalancer extends Resource implements IConnectable { /** * Control all connections from and to this load balancer */ @@ -314,13 +313,6 @@ export class LoadBalancer extends Resource implements IConnectable, codedeploy.I return this.elb.loadBalancerSourceSecurityGroupOwnerAlias; } - public asCodeDeployLoadBalancer(): codedeploy.ILoadBalancerProps { - return { - generation: codedeploy.LoadBalancerGeneration.First, - name: this.loadBalancerName, - }; - } - /** * Allow connections to all existing targets on new instance port */ diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/package.json b/packages/@aws-cdk/aws-elasticloadbalancing/package.json index a8307f7d27f68..3741d61a3eaa2 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/package.json +++ b/packages/@aws-cdk/aws-elasticloadbalancing/package.json @@ -65,13 +65,11 @@ "pkglint": "^0.31.0" }, "dependencies": { - "@aws-cdk/aws-codedeploy-api": "^0.31.0", "@aws-cdk/aws-ec2": "^0.31.0", "@aws-cdk/cdk": "^0.31.0" }, "homepage": "https://github.com/awslabs/aws-cdk", "peerDependencies": { - "@aws-cdk/aws-codedeploy-api": "^0.31.0", "@aws-cdk/aws-ec2": "^0.31.0", "@aws-cdk/cdk": "^0.31.0" }, diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts index 64f2130f6657b..5ab5bfe336231 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts @@ -1,4 +1,3 @@ -import codedeploy = require('@aws-cdk/aws-codedeploy-api'); import ec2 = require('@aws-cdk/aws-ec2'); import cdk = require('@aws-cdk/cdk'); import { CfnTargetGroup } from '../elasticloadbalancingv2.generated'; @@ -131,7 +130,7 @@ export interface HealthCheck { /** * Define the target of a load balancer */ -export abstract class TargetGroupBase extends cdk.Construct implements ITargetGroup, codedeploy.ILoadBalancer { +export abstract class TargetGroupBase extends cdk.Construct implements ITargetGroup { /** * The ARN of the target group */ @@ -275,13 +274,6 @@ export abstract class TargetGroupBase extends cdk.Construct implements ITargetGr }; } - public asCodeDeployLoadBalancer(): codedeploy.ILoadBalancerProps { - return { - generation: codedeploy.LoadBalancerGeneration.Second, - name: this.targetGroupName, - }; - } - /** * Register the given load balancing target as part of this group */ diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/package-lock.json b/packages/@aws-cdk/aws-elasticloadbalancingv2/package-lock.json index 2f7088718bc9b..976f22d031322 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/package-lock.json +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/package-lock.json @@ -94,12 +94,7 @@ "@aws-cdk/aws-iam": "^0.29.0", "@aws-cdk/cdk": "^0.29.0" } - }, - "@aws-cdk/aws-codedeploy-api": { - "version": "0.29.0", - "requires": { - "@aws-cdk/cdk": "^0.29.0" - } + } }, "@aws-cdk/aws-ec2": { "version": "0.29.0", diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json b/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json index 31bb06af43f17..a626c24745499 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json @@ -67,7 +67,6 @@ "dependencies": { "@aws-cdk/aws-certificatemanager": "^0.31.0", "@aws-cdk/aws-cloudwatch": "^0.31.0", - "@aws-cdk/aws-codedeploy-api": "^0.31.0", "@aws-cdk/aws-ec2": "^0.31.0", "@aws-cdk/aws-iam": "^0.31.0", "@aws-cdk/aws-route53": "^0.31.0", @@ -78,7 +77,6 @@ "peerDependencies": { "@aws-cdk/aws-certificatemanager": "^0.31.0", "@aws-cdk/aws-cloudwatch": "^0.31.0", - "@aws-cdk/aws-codedeploy-api": "^0.31.0", "@aws-cdk/aws-ec2": "^0.31.0", "@aws-cdk/aws-iam": "^0.31.0", "@aws-cdk/aws-route53": "^0.31.0", diff --git a/packages/decdk/package.json b/packages/decdk/package.json index 26f763ee21f84..0ab98a9800e86 100644 --- a/packages/decdk/package.json +++ b/packages/decdk/package.json @@ -51,7 +51,6 @@ "@aws-cdk/aws-codebuild": "^0.31.0", "@aws-cdk/aws-codecommit": "^0.31.0", "@aws-cdk/aws-codedeploy": "^0.31.0", - "@aws-cdk/aws-codedeploy-api": "^0.31.0", "@aws-cdk/aws-codepipeline": "^0.31.0", "@aws-cdk/aws-codepipeline-actions": "^0.31.0", "@aws-cdk/aws-cognito": "^0.31.0", @@ -149,4 +148,4 @@ "engines": { "node": ">= 8.10.0" } -} \ No newline at end of file +}