diff --git a/allowed-breaking-changes.txt b/allowed-breaking-changes.txt index fd44c1df2ce34..d85b698a59ce6 100644 --- a/allowed-breaking-changes.txt +++ b/allowed-breaking-changes.txt @@ -19,3 +19,6 @@ removed:@aws-cdk/cdk-assets-schema.FileDestination removed:@aws-cdk/cdk-assets-schema.FileSource removed:@aws-cdk/cdk-assets-schema.ManifestFile removed:@aws-cdk/cdk-assets-schema.FileAssetPackaging + +changed-type:@aws-cdk/aws-codedeploy.IServerDeploymentGroup.autoScalingGroups +changed-type:@aws-cdk/aws-codedeploy.ServerDeploymentGroup.autoScalingGroups diff --git a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts index 157298b8e10b8..07aa86ff45306 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts @@ -390,7 +390,9 @@ abstract class AutoScalingGroupBase extends Resource implements IAutoScalingGrou public abstract autoScalingGroupName: string; public abstract autoScalingGroupArn: string; + public abstract readonly osType: ec2.OperatingSystemType; protected albTargetGroup?: elbv2.ApplicationTargetGroup; + public readonly grantPrincipal: iam.IPrincipal = new iam.UnknownPrincipal({ resource: this }); /** * Send a message to either an SQS queue or SNS topic when instances launch or terminate @@ -490,6 +492,10 @@ abstract class AutoScalingGroupBase extends Resource implements IAutoScalingGrou public scaleOnMetric(id: string, props: BasicStepScalingPolicyProps): StepScalingPolicy { return new StepScalingPolicy(this, id, { ...props, autoScalingGroup: this }); } + + public addUserData(..._commands: string[]): void { + // do nothing + } } /** @@ -508,8 +514,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements elb.ILoadBalancerTarget, ec2.IConnectable, elbv2.IApplicationLoadBalancerTarget, - elbv2.INetworkLoadBalancerTarget, - iam.IGrantable { + elbv2.INetworkLoadBalancerTarget { public static fromAutoScalingGroupName(scope: Construct, id: string, autoScalingGroupName: string): IAutoScalingGroup { class Import extends AutoScalingGroupBase { @@ -519,6 +524,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements resource: 'autoScalingGroup:*:autoScalingGroupName', resourceName: this.autoScalingGroupName, }); + public readonly osType = ec2.OperatingSystemType.UNKNOWN; } return new Import(scope, id); @@ -760,11 +766,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements return { targetType: elbv2.TargetType.INSTANCE }; } - /** - * Add command to the startup script of fleet instances. - * The command must be in the scripting language supported by the fleet's OS (i.e. Linux/Windows). - */ - public addUserData(...commands: string[]) { + public addUserData(...commands: string[]): void { this.userData.addCommands(...commands); } @@ -1121,7 +1123,7 @@ function validatePercentage(x?: number): number | undefined { /** * An AutoScalingGroup */ -export interface IAutoScalingGroup extends IResource { +export interface IAutoScalingGroup extends IResource, iam.IGrantable { /** * The name of the AutoScalingGroup * @attribute @@ -1134,6 +1136,19 @@ export interface IAutoScalingGroup extends IResource { */ readonly autoScalingGroupArn: string; + /** + * The operating system family that the instances in this auto-scaling group belong to. + * Is 'UNKNOWN' for imported ASGs. + */ + readonly osType: ec2.OperatingSystemType; + + /** + * Add command to the startup script of fleet instances. + * The command must be in the scripting language supported by the fleet's OS (i.e. Linux/Windows). + * Does nothing for imported ASGs. + */ + addUserData(...commands: string[]): void; + /** * Send a message to either an SQS queue or SNS topic when instances launch or terminate */ 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 27f1b32fd3a46..3aa3f5915cded 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts @@ -24,7 +24,7 @@ export interface IServerDeploymentGroup extends cdk.IResource { */ readonly deploymentGroupArn: string; readonly deploymentConfig: IServerDeploymentConfig; - readonly autoScalingGroups?: autoscaling.AutoScalingGroup[]; + readonly autoScalingGroups?: autoscaling.IAutoScalingGroup[]; } /** @@ -69,7 +69,7 @@ abstract class ServerDeploymentGroupBase extends cdk.Resource implements IServer public abstract readonly deploymentGroupName: string; public abstract readonly deploymentGroupArn: string; public readonly deploymentConfig: IServerDeploymentConfig; - public abstract readonly autoScalingGroups?: autoscaling.AutoScalingGroup[]; + public abstract readonly autoScalingGroups?: autoscaling.IAutoScalingGroup[]; constructor(scope: cdk.Construct, id: string, deploymentConfig?: IServerDeploymentConfig, props?: cdk.ResourceProps) { super(scope, id, props); @@ -171,7 +171,7 @@ export interface ServerDeploymentGroupProps { * * @default [] */ - readonly autoScalingGroups?: autoscaling.AutoScalingGroup[]; + readonly autoScalingGroups?: autoscaling.IAutoScalingGroup[]; /** * If you've provided any auto-scaling groups with the {@link #autoScalingGroups} property, @@ -258,7 +258,7 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase { public readonly deploymentGroupArn: string; public readonly deploymentGroupName: string; - private readonly _autoScalingGroups: autoscaling.AutoScalingGroup[]; + private readonly _autoScalingGroups: autoscaling.IAutoScalingGroup[]; private readonly installAgent: boolean; private readonly codeDeployBucket: s3.IBucket; private readonly alarms: cloudwatch.IAlarm[]; @@ -333,16 +333,16 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase { this.alarms.push(alarm); } - public get autoScalingGroups(): autoscaling.AutoScalingGroup[] | undefined { + public get autoScalingGroups(): autoscaling.IAutoScalingGroup[] | undefined { return this._autoScalingGroups.slice(); } - private addCodeDeployAgentInstallUserData(asg: autoscaling.AutoScalingGroup): void { + private addCodeDeployAgentInstallUserData(asg: autoscaling.IAutoScalingGroup): void { if (!this.installAgent) { return; } - this.codeDeployBucket.grantRead(asg.role, 'latest/*'); + this.codeDeployBucket.grantRead(asg, 'latest/*'); switch (asg.osType) { case ec2.OperatingSystemType.LINUX: diff --git a/packages/@aws-cdk/aws-codepipeline-actions/lib/codedeploy/server-deploy-action.ts b/packages/@aws-cdk/aws-codepipeline-actions/lib/codedeploy/server-deploy-action.ts index 98606a8aac9a1..07c0662824481 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/lib/codedeploy/server-deploy-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/lib/codedeploy/server-deploy-action.ts @@ -58,7 +58,7 @@ export class CodeDeployServerDeployAction extends Action { // grant the ASG Role permissions to read from the Pipeline Bucket for (const asg of this.deploymentGroup.autoScalingGroups || []) { - options.bucket.grantRead(asg.role); + options.bucket.grantRead(asg); } // the Action's Role needs to read from the Bucket to get artifacts diff --git a/packages/@aws-cdk/aws-ec2/lib/machine-image.ts b/packages/@aws-cdk/aws-ec2/lib/machine-image.ts index c00326888faf8..77834eecac7c1 100644 --- a/packages/@aws-cdk/aws-ec2/lib/machine-image.ts +++ b/packages/@aws-cdk/aws-ec2/lib/machine-image.ts @@ -411,6 +411,11 @@ export class GenericWindowsImage implements IMachineImage { export enum OperatingSystemType { LINUX, WINDOWS, + /** + * Used when the type of the operating system is not known + * (for example, for imported Auto-Scaling Groups). + */ + UNKNOWN, } /** diff --git a/packages/@aws-cdk/aws-ec2/lib/user-data.ts b/packages/@aws-cdk/aws-ec2/lib/user-data.ts index d82754f9e17a8..617563e6cd05a 100644 --- a/packages/@aws-cdk/aws-ec2/lib/user-data.ts +++ b/packages/@aws-cdk/aws-ec2/lib/user-data.ts @@ -89,6 +89,7 @@ export abstract class UserData { switch (os) { case OperatingSystemType.LINUX: return UserData.forLinux(); case OperatingSystemType.WINDOWS: return UserData.forWindows(); + case OperatingSystemType.UNKNOWN: throw new Error('Cannot determine UserData for unknown operating system type'); } } @@ -275,4 +276,4 @@ class CustomUserData extends UserData { public addSignalOnExitCommand(): void { throw new Error('CustomUserData does not support addSignalOnExitCommand, use UserData.forLinux() or UserData.forWindows() instead.'); } -} \ No newline at end of file +}