From d27a13d6fd3932f14e30f7b03efbe5e71b00506b Mon Sep 17 00:00:00 2001 From: Mitchell Valine Date: Wed, 19 Oct 2022 14:24:47 -0700 Subject: [PATCH] fix: breaking change to deployment config props In https://github.com/aws/aws-cdk/pull/22159, a base class for all deployment configs was added. Classes that extended this base were calling static methods returning `IBaseDeploymentConfig` types where previously they returned more specific types, IE `IServerDeploymentConfig`. [This method](https://github.com/aws/aws-cdk/commit/6840d8e43381793bd7a51191bddaffc4cb6641d6#diff-93f73231716deb0056687ee155c13d03ccabe2222fd191a33be9caeb7ad87ebaL126) being previously implemented on `IServerDeploymentConfig` but now inheriting from `IBaseDeploymentConfig` caused the return type to change to `IBaseDeploymentConfig` In Typescript, this is fine as [`IServerDeploymentConfig`](https://github.com/aws/aws-cdk/commit/6840d8e43381793bd7a51191bddaffc4cb6641d6#diff-93f73231716deb0056687ee155c13d03ccabe2222fd191a33be9caeb7ad87ebaR12) extends `IBaseDeploymentConfig` with no additional properties. So an instance of `IBaseDeploymentConfig` satisfies the `IServerDeploymentConfig` interface implicitly. However, in Java where interfaces are explicit, this caused the error: ``` incompatible types: IBaseDeploymentConfig cannot be converted to IServerDeploymentConfig ``` Where inputs expect the more specific type. --- ...loyment-config.ts => deployment-config.ts} | 18 +++++++------- .../lib/ecs/deployment-config.ts | 22 +++-------------- .../lib/ecs/deployment-group.ts | 9 +++---- .../lib/lambda/custom-deployment-config.ts | 4 ++-- .../lib/lambda/deployment-config.ts | 24 ++++--------------- .../lib/lambda/deployment-group.ts | 13 +++++----- .../lib/server/deployment-config.ts | 16 +++---------- .../lib/server/deployment-group.ts | 13 +++++----- 8 files changed, 40 insertions(+), 79 deletions(-) rename packages/@aws-cdk/aws-codedeploy/lib/{base-deployment-config.ts => deployment-config.ts} (89%) diff --git a/packages/@aws-cdk/aws-codedeploy/lib/base-deployment-config.ts b/packages/@aws-cdk/aws-codedeploy/lib/deployment-config.ts similarity index 89% rename from packages/@aws-cdk/aws-codedeploy/lib/base-deployment-config.ts rename to packages/@aws-cdk/aws-codedeploy/lib/deployment-config.ts index 0cd04ae3628c5..20b6a5d9173fe 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/base-deployment-config.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/deployment-config.ts @@ -9,7 +9,7 @@ import { arnForDeploymentConfig, validateName } from './utils'; * The base class for ServerDeploymentConfig, EcsDeploymentConfig, * and LambdaDeploymentConfig deployment configurations. */ -export interface IBaseDeploymentConfig { +export interface IDeploymentConfig { /** * The physical, human-readable name of the Deployment Configuration. * @attribute @@ -24,9 +24,9 @@ export interface IBaseDeploymentConfig { } /** - * Construction properties of {@link BaseDeploymentConfig}. + * Construction properties of {@link DeploymentConfig}. */ -export interface BaseDeploymentConfigOptions { +export interface DeploymentConfigOptions { /** * The physical, human-readable name of the Deployment Configuration. * @default - automatically generated name @@ -56,9 +56,9 @@ export enum ComputePlatform { /** * Complete base deployment config properties that are required to be supplied by the implementation - * of the BaseDeploymentConfig class. + * of the DeploymentConfig class. */ -export interface BaseDeploymentConfigProps extends BaseDeploymentConfigOptions { +export interface DeploymentConfigProps extends DeploymentConfigOptions { /** * The destination compute platform for the deployment. * @@ -86,7 +86,7 @@ export interface BaseDeploymentConfigProps extends BaseDeploymentConfigOptions { * * @resource AWS::CodeDeploy::DeploymentConfig */ -export abstract class BaseDeploymentConfig extends Resource implements IBaseDeploymentConfig { +export abstract class DeploymentConfig extends Resource implements IDeploymentConfig { /** * Import a custom Deployment Configuration for a Deployment Group defined outside the CDK. * @@ -95,7 +95,7 @@ export abstract class BaseDeploymentConfig extends Resource implements IBaseDepl * @param deploymentConfigName the name of the referenced custom Deployment Configuration * @returns a Construct representing a reference to an existing custom Deployment Configuration */ - protected static fromDeploymentConfigName(scope: Construct, id: string, deploymentConfigName: string): IBaseDeploymentConfig { + protected static fromDeploymentConfigName(scope: Construct, id: string, deploymentConfigName: string): IDeploymentConfig { ignore(id); const arn = Stack.of(scope).formatArn({ service: 'codedeploy', @@ -115,7 +115,7 @@ export abstract class BaseDeploymentConfig extends Resource implements IBaseDepl * @param name the name of the referenced custom Deployment Configuration * @returns a reference to an existing custom Deployment Configuration */ - protected static deploymentConfig(name: string): IBaseDeploymentConfig { + protected static deploymentConfig(name: string): IDeploymentConfig { return { deploymentConfigName: name, deploymentConfigArn: arnForDeploymentConfig(name), @@ -134,7 +134,7 @@ export abstract class BaseDeploymentConfig extends Resource implements IBaseDepl */ public readonly deploymentConfigArn: string; - public constructor(scope: Construct, id: string, props?: BaseDeploymentConfigProps) { + public constructor(scope: Construct, id: string, props?: DeploymentConfigProps) { super(scope, id, { physicalName: props?.deploymentConfigName, }); diff --git a/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-config.ts b/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-config.ts index cd1f96aa50945..7b25684fef990 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-config.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-config.ts @@ -1,23 +1,7 @@ import { Construct } from 'constructs'; -import { BaseDeploymentConfig, BaseDeploymentConfigOptions, ComputePlatform, IBaseDeploymentConfig } from '../base-deployment-config'; +import { DeploymentConfig, BaseDeploymentConfigOptions, ComputePlatform, IDeploymentConfig } from '../base-deployment-config'; import { TrafficRouting } from '../traffic-routing-config'; -/** - * The Deployment Configuration of an ECS Deployment Group. - * - * If you're managing the Deployment Configuration alongside the rest of your CDK resources, - * use the {@link EcsDeploymentConfig} class. - * - * If you want to reference an already existing deployment configuration, - * or one defined in a different CDK Stack, - * use the {@link EcsDeploymentConfig#fromEcsDeploymentConfigName} method. - * - * The default, pre-defined Configurations are available as constants on the {@link EcsDeploymentConfig} class - * (for example, `EcsDeploymentConfig.AllAtOnce`). - */ -export interface IEcsDeploymentConfig extends IBaseDeploymentConfig { -} - /** * Construction properties of {@link EcsDeploymentConfig}. */ @@ -35,7 +19,7 @@ export interface EcsDeploymentConfigProps extends BaseDeploymentConfigOptions { * * @resource AWS::CodeDeploy::DeploymentConfig */ -export class EcsDeploymentConfig extends BaseDeploymentConfig implements IEcsDeploymentConfig { +export class EcsDeploymentConfig extends DeploymentConfig { /** CodeDeploy predefined deployment configuration that shifts all traffic to the updated ECS task set at once. */ public static readonly ALL_AT_ONCE = EcsDeploymentConfig.deploymentConfig('CodeDeployDefault.ECSAllAtOnce'); /** CodeDeploy predefined deployment configuration that shifts 10 percent of traffic every minute until all traffic is shifted. */ @@ -55,7 +39,7 @@ export class EcsDeploymentConfig extends BaseDeploymentConfig implements IEcsDep * @param ecsDeploymentConfigName the name of the referenced custom Deployment Configuration * @returns a Construct representing a reference to an existing custom Deployment Configuration */ - public static fromEcsDeploymentConfigName(scope: Construct, id: string, ecsDeploymentConfigName: string): IEcsDeploymentConfig { + public static fromEcsDeploymentConfigName(scope: Construct, id: string, ecsDeploymentConfigName: string): IDeploymentConfig { return this.fromDeploymentConfigName(scope, id, ecsDeploymentConfigName); } diff --git a/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts index 4a432631375e5..de735ba519856 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts @@ -1,8 +1,9 @@ import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; +import { IDeploymentConfig } from '../base-deployment-config'; import { arnForDeploymentGroup } from '../utils'; import { IEcsApplication } from './application'; -import { EcsDeploymentConfig, IEcsDeploymentConfig } from './deployment-config'; +import { EcsDeploymentConfig } from './deployment-config'; /** * Interface for an ECS deployment group. @@ -28,7 +29,7 @@ export interface IEcsDeploymentGroup extends cdk.IResource { /** * The Deployment Configuration this Group uses. */ - readonly deploymentConfig: IEcsDeploymentConfig; + readonly deploymentConfig: IDeploymentConfig; } /** @@ -83,14 +84,14 @@ export interface EcsDeploymentGroupAttributes { * * @default EcsDeploymentConfig.ALL_AT_ONCE */ - readonly deploymentConfig?: IEcsDeploymentConfig; + readonly deploymentConfig?: IDeploymentConfig; } class ImportedEcsDeploymentGroup extends cdk.Resource implements IEcsDeploymentGroup { public readonly application: IEcsApplication; public readonly deploymentGroupName: string; public readonly deploymentGroupArn: string; - public readonly deploymentConfig: IEcsDeploymentConfig; + public readonly deploymentConfig: IDeploymentConfig; constructor(scope:Construct, id: string, props: EcsDeploymentGroupAttributes) { super(scope, id); diff --git a/packages/@aws-cdk/aws-codedeploy/lib/lambda/custom-deployment-config.ts b/packages/@aws-cdk/aws-codedeploy/lib/lambda/custom-deployment-config.ts index fe4ceeb249af2..3fa5e05e539fc 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/lambda/custom-deployment-config.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/lambda/custom-deployment-config.ts @@ -1,8 +1,8 @@ import { Duration, Names, Resource } from '@aws-cdk/core'; import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from '@aws-cdk/custom-resources'; import { Construct } from 'constructs'; +import { IDeploymentConfig } from '../base-deployment-config'; import { arnForDeploymentConfig, validateName } from '../utils'; -import { ILambdaDeploymentConfig } from './deployment-config'; /** * Lambda Deployment config type @@ -64,7 +64,7 @@ export interface CustomLambdaDeploymentConfigProps { * @resource AWS::CodeDeploy::DeploymentGroup * @deprecated CloudFormation now supports Lambda deployment configurations without custom resources. Use {@link LambdaDeploymentConfig}. */ -export class CustomLambdaDeploymentConfig extends Resource implements ILambdaDeploymentConfig { +export class CustomLambdaDeploymentConfig extends Resource implements IDeploymentConfig { /** * The name of the deployment config diff --git a/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-config.ts b/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-config.ts index 18690f239d820..6552d33409fd8 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-config.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-config.ts @@ -1,23 +1,7 @@ import { Construct } from 'constructs'; -import { BaseDeploymentConfig, BaseDeploymentConfigOptions, ComputePlatform, IBaseDeploymentConfig } from '../base-deployment-config'; +import { DeploymentConfig, BaseDeploymentConfigOptions, ComputePlatform, IDeploymentConfig } from '../base-deployment-config'; import { TrafficRouting } from '../traffic-routing-config'; -/** - * The Deployment Configuration of a Lambda Deployment Group. - * - * If you're managing the Deployment Configuration alongside the rest of your CDK resources, - * use the {@link LambdaDeploymentConfig} class. - * - * If you want to reference an already existing deployment configuration, - * or one defined in a different CDK Stack, - * use the {@link LambdaDeploymentConfig#fromLambdaDeploymentConfigName} method. - * - * The default, pre-defined Configurations are available as constants on the {@link LambdaDeploymentConfig} class - * (`LambdaDeploymentConfig.AllAtOnce`, `LambdaDeploymentConfig.Canary10Percent30Minutes`, etc.). - */ -export interface ILambdaDeploymentConfig extends IBaseDeploymentConfig { -} - /** * Properties of a reference to a CodeDeploy Lambda Deployment Configuration. * @@ -47,7 +31,7 @@ export interface LambdaDeploymentConfigProps extends BaseDeploymentConfigOptions * A custom Deployment Configuration for a Lambda Deployment Group. * @resource AWS::CodeDeploy::DeploymentConfig */ -export class LambdaDeploymentConfig extends BaseDeploymentConfig implements ILambdaDeploymentConfig { +export class LambdaDeploymentConfig extends DeploymentConfig { /** CodeDeploy predefined deployment configuration that shifts all traffic to the updated Lambda function at once. */ public static readonly ALL_AT_ONCE = LambdaDeploymentConfig.deploymentConfig('CodeDeployDefault.LambdaAllAtOnce'); /** CodeDeploy predefined deployment configuration that shifts 10 percent of traffic in the first increment. The remaining 90 percent is deployed 30 minutes later. */ @@ -75,7 +59,7 @@ export class LambdaDeploymentConfig extends BaseDeploymentConfig implements ILam * @param lambdaDeploymentConfigName the name of the Lambda Deployment Configuration to import * @returns a Construct representing a reference to an existing Lambda Deployment Configuration */ - public static fromLambdaDeploymentConfigName(scope: Construct, id: string, lambdaDeploymentConfigName: string): ILambdaDeploymentConfig { + public static fromLambdaDeploymentConfigName(scope: Construct, id: string, lambdaDeploymentConfigName: string): IDeploymentConfig { return this.fromDeploymentConfigName(scope, id, lambdaDeploymentConfigName); } @@ -88,7 +72,7 @@ export class LambdaDeploymentConfig extends BaseDeploymentConfig implements ILam * @returns a Construct representing a reference to an existing custom Deployment Configuration * @deprecated use `fromLambdaDeploymentConfigName` */ - public static import(_scope: Construct, _id: string, props: LambdaDeploymentConfigImportProps): ILambdaDeploymentConfig { + public static import(_scope: Construct, _id: string, props: LambdaDeploymentConfigImportProps): IDeploymentConfig { return this.fromLambdaDeploymentConfigName(_scope, _id, props.deploymentConfigName); } diff --git a/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts index 5968402efdd1f..f9aba07125887 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts @@ -3,11 +3,12 @@ import * as iam from '@aws-cdk/aws-iam'; import * as lambda from '@aws-cdk/aws-lambda'; import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; +import { IDeploymentConfig } from '../base-deployment-config'; import { CfnDeploymentGroup } from '../codedeploy.generated'; import { AutoRollbackConfig } from '../rollback-config'; import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration, validateName } from '../utils'; import { ILambdaApplication, LambdaApplication } from './application'; -import { ILambdaDeploymentConfig, LambdaDeploymentConfig } from './deployment-config'; +import { LambdaDeploymentConfig } from './deployment-config'; /** * Interface for a Lambda deployment groups. @@ -33,7 +34,7 @@ export interface ILambdaDeploymentGroup extends cdk.IResource { /** * The Deployment Configuration this Group uses. */ - readonly deploymentConfig: ILambdaDeploymentConfig; + readonly deploymentConfig: IDeploymentConfig; } /** @@ -59,7 +60,7 @@ export interface LambdaDeploymentGroupProps { * * @default LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES */ - readonly deploymentConfig?: ILambdaDeploymentConfig; + readonly deploymentConfig?: IDeploymentConfig; /** * The CloudWatch alarms associated with this Deployment Group. @@ -139,7 +140,7 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy public readonly application: ILambdaApplication; public readonly deploymentGroupName: string; public readonly deploymentGroupArn: string; - public readonly deploymentConfig: ILambdaDeploymentConfig; + public readonly deploymentConfig: IDeploymentConfig; public readonly role: iam.IRole; private readonly alarms: cloudwatch.IAlarm[]; @@ -281,14 +282,14 @@ export interface LambdaDeploymentGroupAttributes { * * @default LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES */ - readonly deploymentConfig?: ILambdaDeploymentConfig; + readonly deploymentConfig?: IDeploymentConfig; } class ImportedLambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploymentGroup { public readonly application: ILambdaApplication; public readonly deploymentGroupName: string; public readonly deploymentGroupArn: string; - public readonly deploymentConfig: ILambdaDeploymentConfig; + public readonly deploymentConfig: IDeploymentConfig; constructor(scope:Construct, id: string, props: LambdaDeploymentGroupAttributes) { super(scope, id); diff --git a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-config.ts b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-config.ts index 97a9357cbe0bc..fd9c0db931485 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-config.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-config.ts @@ -1,17 +1,7 @@ import { Construct } from 'constructs'; -import { BaseDeploymentConfig, BaseDeploymentConfigOptions, IBaseDeploymentConfig } from '../base-deployment-config'; +import { DeploymentConfig, BaseDeploymentConfigOptions, IDeploymentConfig } from '../base-deployment-config'; import { MinimumHealthyHosts } from '../host-health-config'; -/** - * The Deployment Configuration of an EC2/on-premise Deployment Group. - * The default, pre-defined Configurations are available as constants on the {@link ServerDeploymentConfig} class - * (`ServerDeploymentConfig.HALF_AT_A_TIME`, `ServerDeploymentConfig.ALL_AT_ONCE`, etc.). - * To create a custom Deployment Configuration, - * instantiate the {@link ServerDeploymentConfig} Construct. - */ -export interface IServerDeploymentConfig extends IBaseDeploymentConfig { -} - /** * Construction properties of {@link ServerDeploymentConfig}. */ @@ -27,7 +17,7 @@ export interface ServerDeploymentConfigProps extends BaseDeploymentConfigOptions * * @resource AWS::CodeDeploy::DeploymentConfig */ -export class ServerDeploymentConfig extends BaseDeploymentConfig implements IServerDeploymentConfig { +export class ServerDeploymentConfig extends DeploymentConfig { /** * The CodeDeployDefault.OneAtATime predefined deployment configuration for EC2/on-premises compute platform * @@ -59,7 +49,7 @@ export class ServerDeploymentConfig extends BaseDeploymentConfig implements ISer public static fromServerDeploymentConfigName( scope: Construct, id: string, - serverDeploymentConfigName: string): IServerDeploymentConfig { + serverDeploymentConfigName: string): IDeploymentConfig { return this.fromDeploymentConfigName(scope, id, serverDeploymentConfigName); } 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 afb6aee8545e0..601097a940d8f 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts @@ -6,11 +6,12 @@ import * as s3 from '@aws-cdk/aws-s3'; import * as cdk from '@aws-cdk/core'; import { ArnFormat } from '@aws-cdk/core'; import { Construct } from 'constructs'; +import { IDeploymentConfig } from '../base-deployment-config'; import { CfnDeploymentGroup } from '../codedeploy.generated'; import { AutoRollbackConfig } from '../rollback-config'; import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration, validateName } from '../utils'; import { IServerApplication, ServerApplication } from './application'; -import { IServerDeploymentConfig, ServerDeploymentConfig } from './deployment-config'; +import { ServerDeploymentConfig } from './deployment-config'; import { LoadBalancer, LoadBalancerGeneration } from './load-balancer'; export interface IServerDeploymentGroup extends cdk.IResource { @@ -25,7 +26,7 @@ export interface IServerDeploymentGroup extends cdk.IResource { * @attribute */ readonly deploymentGroupArn: string; - readonly deploymentConfig: IServerDeploymentConfig; + readonly deploymentConfig: IDeploymentConfig; readonly autoScalingGroups?: autoscaling.IAutoScalingGroup[]; } @@ -52,7 +53,7 @@ export interface ServerDeploymentGroupAttributes { * * @default ServerDeploymentConfig#OneAtATime */ - readonly deploymentConfig?: IServerDeploymentConfig; + readonly deploymentConfig?: IDeploymentConfig; } /** @@ -70,10 +71,10 @@ abstract class ServerDeploymentGroupBase extends cdk.Resource implements IServer public abstract readonly role?: iam.IRole; public abstract readonly deploymentGroupName: string; public abstract readonly deploymentGroupArn: string; - public readonly deploymentConfig: IServerDeploymentConfig; + public readonly deploymentConfig: IDeploymentConfig; public abstract readonly autoScalingGroups?: autoscaling.IAutoScalingGroup[]; - constructor(scope: Construct, id: string, deploymentConfig?: IServerDeploymentConfig, props?: cdk.ResourceProps) { + constructor(scope: Construct, id: string, deploymentConfig?: IDeploymentConfig, props?: cdk.ResourceProps) { super(scope, id, props); this.deploymentConfig = deploymentConfig || ServerDeploymentConfig.ONE_AT_A_TIME; } @@ -160,7 +161,7 @@ export interface ServerDeploymentGroupProps { * * @default ServerDeploymentConfig#OneAtATime */ - readonly deploymentConfig?: IServerDeploymentConfig; + readonly deploymentConfig?: IDeploymentConfig; /** * The auto-scaling groups belonging to this Deployment Group.