From 1ccc29def98406852c87523916e7ff76658d8a0c Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Tue, 21 Nov 2023 20:16:23 +0900 Subject: [PATCH 01/18] feat(autoscaling): add InstanceMaintenancePolicy property to AutoScalingGroup --- .../aws-autoscaling/lib/auto-scaling-group.ts | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 5d7faa17dbf79..760099410b4ef 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -25,6 +25,7 @@ import { Tokenization, withResolved, } from '../../core'; import { AUTOSCALING_GENERATE_LAUNCH_TEMPLATE } from '../../cx-api'; +import { max } from 'lodash'; /** * Name tag constant @@ -575,6 +576,45 @@ export interface LaunchTemplateOverrides { readonly weightedCapacity?: number } +/** + * InstanceMaintenancePolicy allows you to configure an instance maintenance policy for your Auto Scaling group to + * meet specific capacity requirements during events that cause instances to be replaced, such as an instance + * refresh or the health check process. + * + * https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html + */ +export interface InstanceMaintenancePolicy { + /** + * Specifies the upper threshold as a percentage of the desired capacity of the Auto Scaling group. + * It represents the maximum percentage of the group that can be in service and healthy, or pending, + * to support your workload when replacing instances. + * + * Value range is 100 to 200. After it's set, a value of -1 will clear the previously set value. + * + * Both MinHealthyPercentage and MaxHealthyPercentage must be specified, and the difference between + * them cannot be greater than 100. A large range increases the number of instances that can be + * replaced at the same time. + * + * @default - no value. + */ + readonly maxHealthyPercentage?: number; + + /** + * Specifies the lower threshold as a percentage of the desired capacity of the Auto Scaling group. + * It represents the minimum percentage of the group to keep in service, healthy, and ready to use + * to support your workload when replacing instances. + * + * Value range is 0 to 100. After it's set, a value of -1 will clear the previously set value. + * + * Both MinHealthyPercentage and MaxHealthyPercentage must be specified, and the difference between + * them cannot be greater than 100. A large range increases the number of instances that can be + * replaced at the same time. + * + * @default - no value. + */ + readonly minHealthyPercentage?: number; +} + /** * Properties of a Fleet */ @@ -686,6 +726,13 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * @default false */ readonly requireImdsv2?: boolean; + + /** + * An instance maintenance policy. + * + * @default - no policy. + */ + readonly instanceMaintenancePolicy?: InstanceMaintenancePolicy; } /** @@ -1408,6 +1455,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements })); } + this.validateInstanceMaintenancePolicy(props.instanceMaintenancePolicy); + const { subnetIds, hasPublic } = props.vpc.selectSubnets(props.vpcSubnets); const asgProps: CfnAutoScalingGroupProps = { autoScalingGroupName: this.physicalName, @@ -1427,6 +1476,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements terminationPolicies: props.terminationPolicies, defaultInstanceWarmup: props.defaultInstanceWarmup?.toSeconds(), capacityRebalance: props.capacityRebalance, + instanceMaintenancePolicy: props.instanceMaintenancePolicy, ...this.getLaunchSettings(launchConfig, props.launchTemplate ?? launchTemplateFromConfig, props.mixedInstancesPolicy), }; @@ -1840,6 +1890,43 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements return errors; } + + private validateInstanceMaintenancePolicy(policy: InstanceMaintenancePolicy | undefined) { + if (!policy) { + return; + } + + const maxHealthyPercentage = policy.maxHealthyPercentage + const minHealthyPercentage = policy.minHealthyPercentage + + if ( + maxHealthyPercentage !== undefined + && maxHealthyPercentage !== -1 + && (maxHealthyPercentage < 100 || maxHealthyPercentage > 200) + ) { + throw new Error(`maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthyPercentage}`); + } + if ( + minHealthyPercentage !== undefined + && minHealthyPercentage !== -1 + && (minHealthyPercentage < 0 || minHealthyPercentage > 100) + ) { + throw new Error(`minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthyPercentage}`); + } + if ( + (maxHealthyPercentage !== undefined && minHealthyPercentage === undefined) + || (maxHealthyPercentage === undefined && minHealthyPercentage !== undefined) + ) { + throw new Error(`Both minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: ${minHealthyPercentage} and maxHealthyPercentage: ${maxHealthyPercentage}`); + } + if ( + maxHealthyPercentage !== undefined + && minHealthyPercentage !== undefined + && maxHealthyPercentage - minHealthyPercentage > 100 + ) { + throw new Error(`The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got ${maxHealthyPercentage - minHealthyPercentage}`); + } + } } /** From efc8d38a4df336101fb584ff3e004a6dc69171d3 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Tue, 21 Nov 2023 21:05:52 +0900 Subject: [PATCH 02/18] add unit tests and change validations --- .../aws-autoscaling/lib/auto-scaling-group.ts | 2 + .../test/auto-scaling-group.test.ts | 200 ++++++++++++++++++ 2 files changed, 202 insertions(+) diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 760099410b4ef..99f531eed00b3 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -1922,6 +1922,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements if ( maxHealthyPercentage !== undefined && minHealthyPercentage !== undefined + && maxHealthyPercentage !== -1 + && minHealthyPercentage !== -1 && maxHealthyPercentage - minHealthyPercentage > 100 ) { throw new Error(`The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got ${maxHealthyPercentage - minHealthyPercentage}`); diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts index e6de1020369da..9c84c3686fdf0 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts @@ -2403,6 +2403,206 @@ test('requires imdsv2 when @aws-cdk/aws-autoscaling:generateLaunchTemplateInstea }); }); +test('InstanceMaintenancePolicy can be specified', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: 100, + }, + }); + + // Then + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { + InstanceMaintenancePolicy: { + MaxHealthyPercentage: 200, + MinHealthyPercentage: 100, + }, + }); +}); + +test('maxHealthyPercentage can be set to -1', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: -1, + minHealthyPercentage: 100, + }, + }); + + // Then + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { + InstanceMaintenancePolicy: { + MaxHealthyPercentage: -1, + MinHealthyPercentage: 100, + }, + }); +}); + +test('minHealthyPercentage can be set to -1', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: -1, + }, + }); + + // Then + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { + InstanceMaintenancePolicy: { + MaxHealthyPercentage: 200, + MinHealthyPercentage: -1, + }, + }); +}); + +test('throws if maxHealthyPercentage is greater than 200', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 250, + minHealthyPercentage: 100, + }, + }); + }).toThrow(/maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); +}); + +test('throws if maxHealthyPercentage is less than 100', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 50, + minHealthyPercentage: 100, + }, + }); + }).toThrow(/maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); +}); + +test('throws if minHealthyPercentage is greater than 100', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: 150, + }, + }); + }).toThrow(/minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); +}); + +test('throws if minHealthyPercentage is less than 0', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: -100, + }, + }); + }).toThrow(/minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); +}); + +test('throws if only maxHealthyPercentage is specified', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + }, + }); + }).toThrow(/Both minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: undefined and maxHealthyPercentage: 200/); +}); + +test('throws if only minHealthyPercentage is specified', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + minHealthyPercentage: 100, + }, + }); + }).toThrow(/Both minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: 100 and maxHealthyPercentage: undefined/); +}); + +test('throws if a difference between minHealthyPercentage and maxHealthyPercentage is greater than 100', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: 0, + }, + }); + }).toThrow(/The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got 200/); +}); + function mockSecurityGroup(stack: cdk.Stack) { return ec2.SecurityGroup.fromSecurityGroupId(stack, 'MySG', 'most-secure'); } From d18c78aed84d363da522da5133319545a6012b70 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Tue, 21 Nov 2023 21:20:40 +0900 Subject: [PATCH 03/18] change README --- .../aws-cdk-lib/aws-autoscaling/README.md | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index 4fbbafe1a6bc6..dac0db245b8c9 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -288,6 +288,38 @@ autoScalingGroup.scaleOnSchedule('AllowDownscalingAtNight', { }); ``` +### Instance Maintenance Policy + +The `instanceMaintenancePolicy` allows you to configure an instance maintenance policy for +your Auto Scaling group to meet specific capacity requirements during events that cause +instances to be replaced, such as an instance refresh or the health check process. + +For example, suppose you have an Auto Scaling group that has a small number of instances. +You want to avoid the potential disruptions from terminating and then replacing an instance +when health checks indicate an impaired instance. With an instance maintenance policy, you +can make sure that Amazon EC2 Auto Scaling first launches a new instance and then waits for +it to be fully ready before terminating the unhealthy instance. + +An instance maintenance policy also helps you minimize any potential disruptions in cases +where multiple instances are replaced at the same time. You set the `minHealthyPercentage` +and the `maxHealthyPercentage` for the policy, and your Auto Scaling group can only +increase and decrease capacity within that minimum-maximum range when replacing instances. +A larger range increases the number of instances that can be replaced at the same time. + +```ts +declare const vpc: ec2.Vpc; + +new autoscaling.AutoScalingGroup(this, 'ASG', { + vpc, + instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: 100, + }, +}); +``` + ### Block Devices This type specifies how block devices are exposed to the instance. You can specify virtual devices and EBS volumes. From 042b4b7636f95c50a97dec23628ce085a07bfc30 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Tue, 21 Nov 2023 21:20:54 +0900 Subject: [PATCH 04/18] add an integ test --- ...efaultTestDeployAssertD50B51FD.assets.json | 19 + ...aultTestDeployAssertD50B51FD.template.json | 36 + ...ng-instance-maintenance-policy.assets.json | 19 + ...-instance-maintenance-policy.template.json | 593 ++++++++++ .../cdk.out | 1 + .../integ.json | 12 + .../manifest.json | 281 +++++ .../tree.json | 1008 +++++++++++++++++ .../integ.asg-instance-maintenance-policy.ts | 29 + .../aws-autoscaling/lib/auto-scaling-group.ts | 1 - 10 files changed, 1998 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.assets.json new file mode 100644 index 0000000000000..b7155eed0e6de --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.assets.json @@ -0,0 +1,19 @@ +{ + "version": "35.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.assets.json new file mode 100644 index 0000000000000..1d92a38b1511c --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.assets.json @@ -0,0 +1,19 @@ +{ + "version": "35.0.0", + "files": { + "4dec940604e66b5e8a991fa69a0808e304f6f584fa5f51f6ba503a61df33a1b4": { + "source": { + "path": "aws-cdk-autoscaling-instance-maintenance-policy.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "4dec940604e66b5e8a991fa69a0808e304f6f584fa5f51f6ba503a61df33a1b4.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.template.json new file mode 100644 index 0000000000000..161df40828add --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.template.json @@ -0,0 +1,593 @@ +{ + "Resources": { + "VPCB9E5F0B4": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC" + } + ] + } + }, + "VPCPublicSubnet1SubnetB4246D30": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.0.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1" + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "VPCPublicSubnet1RouteTableFEE4B781": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1" + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "VPCPublicSubnet1RouteTableAssociation0B0896DC": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" + }, + "SubnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + } + } + }, + "VPCPublicSubnet1DefaultRoute91CEF279": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VPCIGWB7E252D3" + }, + "RouteTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" + } + }, + "DependsOn": [ + "VPCVPCGW99B986DC" + ] + }, + "VPCPublicSubnet1EIP6AD938E8": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1" + } + ] + } + }, + "VPCPublicSubnet1NATGatewayE0556630": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "VPCPublicSubnet1EIP6AD938E8", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1" + } + ] + }, + "DependsOn": [ + "VPCPublicSubnet1DefaultRoute91CEF279", + "VPCPublicSubnet1RouteTableAssociation0B0896DC" + ] + }, + "VPCPublicSubnet2Subnet74179F39": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.64.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2" + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "VPCPublicSubnet2RouteTable6F1A15F1": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2" + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "VPCPublicSubnet2RouteTableAssociation5A808732": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" + }, + "SubnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + } + } + }, + "VPCPublicSubnet2DefaultRouteB7481BBA": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VPCIGWB7E252D3" + }, + "RouteTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" + } + }, + "DependsOn": [ + "VPCVPCGW99B986DC" + ] + }, + "VPCPublicSubnet2EIP4947BC00": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2" + } + ] + } + }, + "VPCPublicSubnet2NATGateway3C070193": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "VPCPublicSubnet2EIP4947BC00", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2" + } + ] + }, + "DependsOn": [ + "VPCPublicSubnet2DefaultRouteB7481BBA", + "VPCPublicSubnet2RouteTableAssociation5A808732" + ] + }, + "VPCPrivateSubnet1Subnet8BCA10E0": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.128.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1" + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "VPCPrivateSubnet1RouteTableBE8A6027": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1" + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "VPCPrivateSubnet1RouteTableAssociation347902D1": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" + }, + "SubnetId": { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + } + } + }, + "VPCPrivateSubnet1DefaultRouteAE1D6490": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VPCPublicSubnet1NATGatewayE0556630" + }, + "RouteTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" + } + } + }, + "VPCPrivateSubnet2SubnetCFCDAA7A": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.192.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2" + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "VPCPrivateSubnet2RouteTable0A19E10E": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2" + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "VPCPrivateSubnet2RouteTableAssociation0C73D413": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" + }, + "SubnetId": { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + } + }, + "VPCPrivateSubnet2DefaultRouteF4F5CFD2": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VPCPublicSubnet2NATGateway3C070193" + }, + "RouteTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" + } + } + }, + "VPCIGWB7E252D3": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC" + } + ] + } + }, + "VPCVPCGW99B986DC": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "InternetGatewayId": { + "Ref": "VPCIGWB7E252D3" + }, + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "ASGInstanceSecurityGroup0525485D": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceSecurityGroup", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG" + } + ], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "ASGInstanceRoleE263A41B": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG" + } + ] + } + }, + "ASGInstanceProfile0A2834D7": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "ASGInstanceRoleE263A41B" + } + ] + } + }, + "ASGLaunchTemplate0CA92847": { + "Type": "AWS::EC2::LaunchTemplate", + "Properties": { + "LaunchTemplateData": { + "IamInstanceProfile": { + "Arn": { + "Fn::GetAtt": [ + "ASGInstanceProfile0A2834D7", + "Arn" + ] + } + }, + "ImageId": { + "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + }, + "InstanceType": "t2.micro", + "Monitoring": { + "Enabled": false + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "ASGInstanceSecurityGroup0525485D", + "GroupId" + ] + } + ], + "TagSpecifications": [ + { + "ResourceType": "instance", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/LaunchTemplate" + } + ] + }, + { + "ResourceType": "volume", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/LaunchTemplate" + } + ] + } + ], + "UserData": { + "Fn::Base64": "#!/bin/bash" + } + }, + "TagSpecifications": [ + { + "ResourceType": "launch-template", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/LaunchTemplate" + } + ] + } + ] + }, + "DependsOn": [ + "ASGInstanceRoleE263A41B" + ] + }, + "ASG46ED3070": { + "Type": "AWS::AutoScaling::AutoScalingGroup", + "Properties": { + "LaunchTemplate": { + "LaunchTemplateId": { + "Ref": "ASGLaunchTemplate0CA92847" + }, + "Version": { + "Fn::GetAtt": [ + "ASGLaunchTemplate0CA92847", + "LatestVersionNumber" + ] + } + }, + "MaxSize": "1", + "MinSize": "1", + "Tags": [ + { + "Key": "Name", + "PropagateAtLaunch": true, + "Value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG" + } + ], + "VPCZoneIdentifier": [ + { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + }, + { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + ] + }, + "UpdatePolicy": { + "AutoScalingScheduledAction": { + "IgnoreUnmodifiedGroupSizeProperties": true + } + } + } + }, + "Parameters": { + "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2" + }, + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/cdk.out new file mode 100644 index 0000000000000..c5cb2e5de6344 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"35.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/integ.json new file mode 100644 index 0000000000000..fad2dcd371b8d --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "35.0.0", + "testCases": { + "InstanceMaintenancePolicyTest/DefaultTest": { + "stacks": [ + "aws-cdk-autoscaling-instance-maintenance-policy" + ], + "assertionStack": "InstanceMaintenancePolicyTest/DefaultTest/DeployAssert", + "assertionStackName": "InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/manifest.json new file mode 100644 index 0000000000000..9baab086ec3c7 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/manifest.json @@ -0,0 +1,281 @@ +{ + "version": "35.0.0", + "artifacts": { + "aws-cdk-autoscaling-instance-maintenance-policy.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "aws-cdk-autoscaling-instance-maintenance-policy.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "aws-cdk-autoscaling-instance-maintenance-policy": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "aws-cdk-autoscaling-instance-maintenance-policy.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/4dec940604e66b5e8a991fa69a0808e304f6f584fa5f51f6ba503a61df33a1b4.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "aws-cdk-autoscaling-instance-maintenance-policy.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "aws-cdk-autoscaling-instance-maintenance-policy.assets" + ], + "metadata": { + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCB9E5F0B4" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1SubnetB4246D30" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1RouteTableFEE4B781" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1RouteTableAssociation0B0896DC" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1DefaultRoute91CEF279" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1EIP6AD938E8" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet1NATGatewayE0556630" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2Subnet74179F39" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2RouteTable6F1A15F1" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2RouteTableAssociation5A808732" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2DefaultRouteB7481BBA" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2EIP4947BC00" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPublicSubnet2NATGateway3C070193" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet1Subnet8BCA10E0" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet1RouteTableBE8A6027" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet1RouteTableAssociation347902D1" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet1DefaultRouteAE1D6490" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet2RouteTable0A19E10E" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet2RouteTableAssociation0C73D413" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCPrivateSubnet2DefaultRouteF4F5CFD2" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/IGW": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCIGWB7E252D3" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/VPC/VPCGW": [ + { + "type": "aws:cdk:logicalId", + "data": "VPCVPCGW99B986DC" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceSecurityGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ASGInstanceSecurityGroup0525485D" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ASGInstanceRoleE263A41B" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceProfile": [ + { + "type": "aws:cdk:logicalId", + "data": "ASGInstanceProfile0A2834D7" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/ASG/LaunchTemplate/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ASGLaunchTemplate0CA92847" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/ASG/ASG": [ + { + "type": "aws:cdk:logicalId", + "data": "ASG46ED3070" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [ + { + "type": "aws:cdk:logicalId", + "data": "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/aws-cdk-autoscaling-instance-maintenance-policy/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "aws-cdk-autoscaling-instance-maintenance-policy" + }, + "InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "InstanceMaintenancePolicyTestDefaultTestDeployAssertD50B51FD.assets" + ], + "metadata": { + "/InstanceMaintenancePolicyTest/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/InstanceMaintenancePolicyTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "InstanceMaintenancePolicyTest/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/tree.json new file mode 100644 index 0000000000000..4b8369b916f95 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/tree.json @@ -0,0 +1,1008 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "aws-cdk-autoscaling-instance-maintenance-policy": { + "id": "aws-cdk-autoscaling-instance-maintenance-policy", + "path": "aws-cdk-autoscaling-instance-maintenance-policy", + "children": { + "VPC": { + "id": "VPC", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPC", + "aws:cdk:cloudformation:props": { + "cidrBlock": "10.0.0.0/16", + "enableDnsHostnames": true, + "enableDnsSupport": true, + "instanceTenancy": "default", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnVPC", + "version": "0.0.0" + } + }, + "PublicSubnet1": { + "id": "PublicSubnet1", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.0.0/18", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" + }, + "subnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VPCIGWB7E252D3" + }, + "routeTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "VPCPublicSubnet1EIP6AD938E8", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PublicSubnet2": { + "id": "PublicSubnet2", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.64.0/18", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" + }, + "subnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VPCIGWB7E252D3" + }, + "routeTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "VPCPublicSubnet2EIP4947BC00", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet1": { + "id": "PrivateSubnet1", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.128.0/18", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" + }, + "subnetId": { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VPCPublicSubnet1NATGatewayE0556630" + }, + "routeTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet2": { + "id": "PrivateSubnet2", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.192.0/18", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" + }, + "subnetId": { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VPCPublicSubnet2NATGateway3C070193" + }, + "routeTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "IGW": { + "id": "IGW", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/IGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::InternetGateway", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/VPC" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnInternetGateway", + "version": "0.0.0" + } + }, + "VPCGW": { + "id": "VPCGW", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/VPCGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPCGatewayAttachment", + "aws:cdk:cloudformation:props": { + "internetGatewayId": { + "Ref": "VPCIGWB7E252D3" + }, + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnVPCGatewayAttachment", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.Vpc", + "version": "0.0.0" + } + }, + "ASG": { + "id": "ASG", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG", + "children": { + "InstanceSecurityGroup": { + "id": "InstanceSecurityGroup", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceSecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceSecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceSecurityGroup", + "securityGroupEgress": [ + { + "cidrIp": "0.0.0.0/0", + "description": "Allow all outbound traffic by default", + "ipProtocol": "-1" + } + ], + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG" + } + ], + "vpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", + "version": "0.0.0" + } + }, + "InstanceRole": { + "id": "InstanceRole", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceRole", + "children": { + "ImportInstanceRole": { + "id": "ImportInstanceRole", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceRole/ImportInstanceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "InstanceProfile": { + "id": "InstanceProfile", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceProfile", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::InstanceProfile", + "aws:cdk:cloudformation:props": { + "roles": [ + { + "Ref": "ASGInstanceRoleE263A41B" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnInstanceProfile", + "version": "0.0.0" + } + }, + "ImportedInstanceProfile": { + "id": "ImportedInstanceProfile", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/ImportedInstanceProfile", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "LaunchTemplate": { + "id": "LaunchTemplate", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/LaunchTemplate", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/LaunchTemplate/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::LaunchTemplate", + "aws:cdk:cloudformation:props": { + "launchTemplateData": { + "iamInstanceProfile": { + "arn": { + "Fn::GetAtt": [ + "ASGInstanceProfile0A2834D7", + "Arn" + ] + } + }, + "imageId": { + "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + }, + "instanceType": "t2.micro", + "monitoring": { + "enabled": false + }, + "securityGroupIds": [ + { + "Fn::GetAtt": [ + "ASGInstanceSecurityGroup0525485D", + "GroupId" + ] + } + ], + "tagSpecifications": [ + { + "resourceType": "instance", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/LaunchTemplate" + } + ] + }, + { + "resourceType": "volume", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/LaunchTemplate" + } + ] + } + ], + "userData": { + "Fn::Base64": "#!/bin/bash" + } + }, + "tagSpecifications": [ + { + "resourceType": "launch-template", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/LaunchTemplate" + } + ] + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnLaunchTemplate", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.LaunchTemplate", + "version": "0.0.0" + } + }, + "ASG": { + "id": "ASG", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/ASG", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::AutoScaling::AutoScalingGroup", + "aws:cdk:cloudformation:props": { + "launchTemplate": { + "launchTemplateId": { + "Ref": "ASGLaunchTemplate0CA92847" + }, + "version": { + "Fn::GetAtt": [ + "ASGLaunchTemplate0CA92847", + "LatestVersionNumber" + ] + } + }, + "maxSize": "1", + "minSize": "1", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-autoscaling-instance-maintenance-policy/ASG", + "propagateAtLaunch": true + } + ], + "vpcZoneIdentifier": [ + { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + }, + { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_autoscaling.CfnAutoScalingGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_autoscaling.AutoScalingGroup", + "version": "0.0.0" + } + }, + "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": { + "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118": { + "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "aws-cdk-autoscaling-instance-maintenance-policy/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "InstanceMaintenancePolicyTest": { + "id": "InstanceMaintenancePolicyTest", + "path": "InstanceMaintenancePolicyTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "InstanceMaintenancePolicyTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "InstanceMaintenancePolicyTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "InstanceMaintenancePolicyTest/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "InstanceMaintenancePolicyTest/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "InstanceMaintenancePolicyTest/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts new file mode 100644 index 0000000000000..613c55f59c528 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts @@ -0,0 +1,29 @@ +#!/usr/bin/env node +import * as ec2 from 'aws-cdk-lib/aws-ec2'; +import * as cdk from 'aws-cdk-lib'; +import * as integ from '@aws-cdk/integ-tests-alpha'; +import * as autoscaling from 'aws-cdk-lib/aws-autoscaling'; + +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'aws-cdk-autoscaling-instance-maintenance-policy'); + +const vpc = new ec2.Vpc(stack, 'VPC', { + maxAzs: 2, + restrictDefaultSecurityGroup: false, +}); + +new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: 100, + }, +}); + +new integ.IntegTest(app, 'InstanceMaintenancePolicyTest', { + testCases: [stack], +}); + +app.synth(); diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 99f531eed00b3..867d66baf6400 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -25,7 +25,6 @@ import { Tokenization, withResolved, } from '../../core'; import { AUTOSCALING_GENERATE_LAUNCH_TEMPLATE } from '../../cx-api'; -import { max } from 'lodash'; /** * Name tag constant From ef4db98cacdc8b0fe66757a73b36e044c222d98e Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Tue, 21 Nov 2023 21:47:38 +0900 Subject: [PATCH 05/18] fix to add semicolons --- .../aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 867d66baf6400..e7cc0dde2cef9 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -1895,8 +1895,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements return; } - const maxHealthyPercentage = policy.maxHealthyPercentage - const minHealthyPercentage = policy.minHealthyPercentage + const maxHealthyPercentage = policy.maxHealthyPercentage; + const minHealthyPercentage = policy.minHealthyPercentage; if ( maxHealthyPercentage !== undefined From 29a85ed1c87a560f864992471ced9f912ddce839 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Tue, 21 Nov 2023 22:57:39 +0900 Subject: [PATCH 06/18] change integ snapshots --- ...ng-instance-maintenance-policy.assets.json | 4 +- ...-instance-maintenance-policy.template.json | 4 + .../manifest.json | 2 +- .../tree.json | 212 +++++++++--------- 4 files changed, 115 insertions(+), 107 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.assets.json index 1d92a38b1511c..6990451f9edcc 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.assets.json @@ -1,7 +1,7 @@ { "version": "35.0.0", "files": { - "4dec940604e66b5e8a991fa69a0808e304f6f584fa5f51f6ba503a61df33a1b4": { + "552655a270c3cb8ae8062ae2b35081cf3834c5522f3cd7d70534262f48610fbd": { "source": { "path": "aws-cdk-autoscaling-instance-maintenance-policy.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "4dec940604e66b5e8a991fa69a0808e304f6f584fa5f51f6ba503a61df33a1b4.json", + "objectKey": "552655a270c3cb8ae8062ae2b35081cf3834c5522f3cd7d70534262f48610fbd.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.template.json index 161df40828add..aad708ff0fc8d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/aws-cdk-autoscaling-instance-maintenance-policy.template.json @@ -516,6 +516,10 @@ "ASG46ED3070": { "Type": "AWS::AutoScaling::AutoScalingGroup", "Properties": { + "InstanceMaintenancePolicy": { + "MaxHealthyPercentage": 200, + "MinHealthyPercentage": 100 + }, "LaunchTemplate": { "LaunchTemplateId": { "Ref": "ASGLaunchTemplate0CA92847" diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/manifest.json index 9baab086ec3c7..ff40a4f05db6a 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/4dec940604e66b5e8a991fa69a0808e304f6f584fa5f51f6ba503a61df33a1b4.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/552655a270c3cb8ae8062ae2b35081cf3834c5522f3cd7d70534262f48610fbd.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/tree.json index 4b8369b916f95..78f272dcf815f 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.js.snapshot/tree.json @@ -31,8 +31,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnVPC", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "PublicSubnet1": { @@ -75,16 +75,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Acl": { "id": "Acl", "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet1/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTable": { @@ -105,8 +105,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTableAssociation": { @@ -124,8 +124,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultRoute": { @@ -144,8 +144,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "EIP": { @@ -164,8 +164,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "NATGateway": { @@ -192,14 +192,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "PublicSubnet2": { @@ -242,16 +242,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Acl": { "id": "Acl", "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PublicSubnet2/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTable": { @@ -272,8 +272,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTableAssociation": { @@ -291,8 +291,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultRoute": { @@ -311,8 +311,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "EIP": { @@ -331,8 +331,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "NATGateway": { @@ -359,14 +359,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "PrivateSubnet1": { @@ -409,16 +409,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Acl": { "id": "Acl", "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet1/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTable": { @@ -439,8 +439,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTableAssociation": { @@ -458,8 +458,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultRoute": { @@ -478,14 +478,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "PrivateSubnet2": { @@ -528,16 +528,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Acl": { "id": "Acl", "path": "aws-cdk-autoscaling-instance-maintenance-policy/VPC/PrivateSubnet2/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTable": { @@ -558,8 +558,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTableAssociation": { @@ -577,8 +577,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultRoute": { @@ -597,14 +597,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "IGW": { @@ -622,8 +622,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnInternetGateway", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "VPCGW": { @@ -641,14 +641,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnVPCGatewayAttachment", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.Vpc", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "ASG": { @@ -685,14 +685,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "InstanceRole": { @@ -703,8 +703,8 @@ "id": "ImportInstanceRole", "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/InstanceRole/ImportInstanceRole", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Resource": { @@ -734,14 +734,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnRole", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "InstanceProfile": { @@ -758,16 +758,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnInstanceProfile", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "ImportedInstanceProfile": { "id": "ImportedInstanceProfile", "path": "aws-cdk-autoscaling-instance-maintenance-policy/ASG/ImportedInstanceProfile", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "LaunchTemplate": { @@ -842,14 +842,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnLaunchTemplate", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.LaunchTemplate", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "ASG": { @@ -858,6 +858,10 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::AutoScaling::AutoScalingGroup", "aws:cdk:cloudformation:props": { + "instanceMaintenancePolicy": { + "maxHealthyPercentage": 200, + "minHealthyPercentage": 100 + }, "launchTemplate": { "launchTemplateId": { "Ref": "ASGLaunchTemplate0CA92847" @@ -889,52 +893,52 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_autoscaling.CfnAutoScalingGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_autoscaling.AutoScalingGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "path": "aws-cdk-autoscaling-instance-maintenance-policy/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118": { "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "path": "aws-cdk-autoscaling-instance-maintenance-policy/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "BootstrapVersion": { "id": "BootstrapVersion", "path": "aws-cdk-autoscaling-instance-maintenance-policy/BootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "aws-cdk-autoscaling-instance-maintenance-policy/CheckBootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "InstanceMaintenancePolicyTest": { @@ -961,22 +965,22 @@ "id": "BootstrapVersion", "path": "InstanceMaintenancePolicyTest/DefaultTest/DeployAssert/BootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "InstanceMaintenancePolicyTest/DefaultTest/DeployAssert/CheckBootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, @@ -1001,8 +1005,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.App", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } } \ No newline at end of file From 8f8f6f1270101afdb8e6ab98a5f540824136268b Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 22 Nov 2023 00:49:55 +0900 Subject: [PATCH 07/18] change goc --- .../aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index e7cc0dde2cef9..b59aad171c135 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -590,7 +590,7 @@ export interface InstanceMaintenancePolicy { * * Value range is 100 to 200. After it's set, a value of -1 will clear the previously set value. * - * Both MinHealthyPercentage and MaxHealthyPercentage must be specified, and the difference between + * Both `minHealthyPercentage` and `maxHealthyPercentage` must be specified, and the difference between * them cannot be greater than 100. A large range increases the number of instances that can be * replaced at the same time. * @@ -605,7 +605,7 @@ export interface InstanceMaintenancePolicy { * * Value range is 0 to 100. After it's set, a value of -1 will clear the previously set value. * - * Both MinHealthyPercentage and MaxHealthyPercentage must be specified, and the difference between + * Both `minHealthyPercentage` and `maxHealthyPercentage` must be specified, and the difference between * them cannot be greater than 100. A large range increases the number of instances that can be * replaced at the same time. * From 5814463fd685c4003fde98d3745a09ccfc8e90a5 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 22 Nov 2023 00:55:42 +0900 Subject: [PATCH 08/18] change doc for instanceMaintenancePolicy --- packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index b59aad171c135..d79142f877ce6 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -729,7 +729,7 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { /** * An instance maintenance policy. * - * @default - no policy. + * @default - no instance maintenance policy. */ readonly instanceMaintenancePolicy?: InstanceMaintenancePolicy; } From b4ef9f73063d5daaa83fd990310fc31842a580ef Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 22 Nov 2023 13:17:40 +0900 Subject: [PATCH 09/18] fix by the review fix by the review add new validation to clear previously set values add new unit tests --- .../aws-cdk-lib/aws-autoscaling/README.md | 2 + .../aws-autoscaling/lib/auto-scaling-group.ts | 41 +-- .../test/auto-scaling-group.test.ts | 321 ++++++++---------- 3 files changed, 163 insertions(+), 201 deletions(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index dac0db245b8c9..8fc9c48003826 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -320,6 +320,8 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { }); ``` +> Visit [Instance maintenance policies](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html) for more details. + ### Block Devices This type specifies how block devices are exposed to the instance. You can specify virtual devices and EBS volumes. diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index d79142f877ce6..6454ac0c0a884 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -576,11 +576,11 @@ export interface LaunchTemplateOverrides { } /** - * InstanceMaintenancePolicy allows you to configure an instance maintenance policy for your Auto Scaling group to + * Allows you to configure an instance maintenance policy for your Auto Scaling group to * meet specific capacity requirements during events that cause instances to be replaced, such as an instance * refresh or the health check process. * - * https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html + * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html */ export interface InstanceMaintenancePolicy { /** @@ -593,10 +593,8 @@ export interface InstanceMaintenancePolicy { * Both `minHealthyPercentage` and `maxHealthyPercentage` must be specified, and the difference between * them cannot be greater than 100. A large range increases the number of instances that can be * replaced at the same time. - * - * @default - no value. */ - readonly maxHealthyPercentage?: number; + readonly maxHealthyPercentage: number; /** * Specifies the lower threshold as a percentage of the desired capacity of the Auto Scaling group. @@ -608,10 +606,8 @@ export interface InstanceMaintenancePolicy { * Both `minHealthyPercentage` and `maxHealthyPercentage` must be specified, and the difference between * them cannot be greater than 100. A large range increases the number of instances that can be * replaced at the same time. - * - * @default - no value. */ - readonly minHealthyPercentage?: number; + readonly minHealthyPercentage: number; } /** @@ -1890,7 +1886,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements return errors; } - private validateInstanceMaintenancePolicy(policy: InstanceMaintenancePolicy | undefined) { + private validateInstanceMaintenancePolicy(policy?: InstanceMaintenancePolicy) { if (!policy) { return; } @@ -1898,33 +1894,16 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements const maxHealthyPercentage = policy.maxHealthyPercentage; const minHealthyPercentage = policy.minHealthyPercentage; - if ( - maxHealthyPercentage !== undefined - && maxHealthyPercentage !== -1 - && (maxHealthyPercentage < 100 || maxHealthyPercentage > 200) - ) { + if (maxHealthyPercentage !== -1 && (maxHealthyPercentage < 100 || maxHealthyPercentage > 200)) { throw new Error(`maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthyPercentage}`); } - if ( - minHealthyPercentage !== undefined - && minHealthyPercentage !== -1 - && (minHealthyPercentage < 0 || minHealthyPercentage > 100) - ) { + if (minHealthyPercentage !== -1 && (minHealthyPercentage < 0 || minHealthyPercentage > 100)) { throw new Error(`minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthyPercentage}`); } - if ( - (maxHealthyPercentage !== undefined && minHealthyPercentage === undefined) - || (maxHealthyPercentage === undefined && minHealthyPercentage !== undefined) - ) { - throw new Error(`Both minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: ${minHealthyPercentage} and maxHealthyPercentage: ${maxHealthyPercentage}`); + if ((maxHealthyPercentage !== -1 && minHealthyPercentage === -1) || (maxHealthyPercentage === -1 && minHealthyPercentage !== -1)) { + throw new Error(`Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: ${minHealthyPercentage} and maxHealthyPercentage: ${maxHealthyPercentage}`); } - if ( - maxHealthyPercentage !== undefined - && minHealthyPercentage !== undefined - && maxHealthyPercentage !== -1 - && minHealthyPercentage !== -1 - && maxHealthyPercentage - minHealthyPercentage > 100 - ) { + if (maxHealthyPercentage !== -1 && minHealthyPercentage !== -1 && maxHealthyPercentage - minHealthyPercentage > 100) { throw new Error(`The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got ${maxHealthyPercentage - minHealthyPercentage}`); } } diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts index 9c84c3686fdf0..fd0276a267d2c 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts @@ -2403,204 +2403,185 @@ test('requires imdsv2 when @aws-cdk/aws-autoscaling:generateLaunchTemplateInstea }); }); -test('InstanceMaintenancePolicy can be specified', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = mockVpc(stack); - new autoscaling.AutoScalingGroup(stack, 'ASG', { - vpc, - instanceType: new ec2.InstanceType('t2.micro'), - machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: 100, - }, - }); - - // Then - Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { - InstanceMaintenancePolicy: { - MaxHealthyPercentage: 200, - MinHealthyPercentage: 100, - }, - }); -}); - -test('maxHealthyPercentage can be set to -1', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = mockVpc(stack); - new autoscaling.AutoScalingGroup(stack, 'ASG', { - vpc, - instanceType: new ec2.InstanceType('t2.micro'), - machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: -1, - minHealthyPercentage: 100, - }, - }); - - // Then - Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { - InstanceMaintenancePolicy: { - MaxHealthyPercentage: -1, - MinHealthyPercentage: 100, - }, - }); -}); - -test('minHealthyPercentage can be set to -1', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = mockVpc(stack); - new autoscaling.AutoScalingGroup(stack, 'ASG', { - vpc, - instanceType: new ec2.InstanceType('t2.micro'), - machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: -1, - }, - }); - - // Then - Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { - InstanceMaintenancePolicy: { - MaxHealthyPercentage: 200, - MinHealthyPercentage: -1, - }, - }); -}); - -test('throws if maxHealthyPercentage is greater than 200', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = mockVpc(stack); - - // Then - expect(() => { +describe('InstanceMaintenancePolicy', () => { + test('InstanceMaintenancePolicy can be specified', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); new autoscaling.AutoScalingGroup(stack, 'ASG', { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), instanceMaintenancePolicy: { - maxHealthyPercentage: 250, + maxHealthyPercentage: 200, minHealthyPercentage: 100, }, }); - }).toThrow(/maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); -}); - -test('throws if maxHealthyPercentage is less than 100', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = mockVpc(stack); - // Then - expect(() => { - new autoscaling.AutoScalingGroup(stack, 'ASG', { - vpc, - instanceType: new ec2.InstanceType('t2.micro'), - machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 50, - minHealthyPercentage: 100, + // Then + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { + InstanceMaintenancePolicy: { + MaxHealthyPercentage: 200, + MinHealthyPercentage: 100, }, }); - }).toThrow(/maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); -}); - -test('throws if minHealthyPercentage is greater than 100', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = mockVpc(stack); + }); - // Then - expect(() => { + test('maxHealthyPercentage and minHealthyPercentage can be set to -1', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); new autoscaling.AutoScalingGroup(stack, 'ASG', { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: 150, + maxHealthyPercentage: -1, + minHealthyPercentage: -1, }, }); - }).toThrow(/minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); -}); - -test('throws if minHealthyPercentage is less than 0', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = mockVpc(stack); - // Then - expect(() => { - new autoscaling.AutoScalingGroup(stack, 'ASG', { - vpc, - instanceType: new ec2.InstanceType('t2.micro'), - machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: -100, + // Then + Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { + InstanceMaintenancePolicy: { + MaxHealthyPercentage: -1, + MinHealthyPercentage: -1, }, }); - }).toThrow(/minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); -}); + }); -test('throws if only maxHealthyPercentage is specified', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = mockVpc(stack); + test('throws if maxHealthyPercentage is greater than 200', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); - // Then - expect(() => { - new autoscaling.AutoScalingGroup(stack, 'ASG', { - vpc, - instanceType: new ec2.InstanceType('t2.micro'), - machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - }, - }); - }).toThrow(/Both minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: undefined and maxHealthyPercentage: 200/); -}); + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 250, + minHealthyPercentage: 100, + }, + }); + }).toThrow(/maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); + }); -test('throws if only minHealthyPercentage is specified', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = mockVpc(stack); + test('throws if maxHealthyPercentage is less than 100', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); - // Then - expect(() => { - new autoscaling.AutoScalingGroup(stack, 'ASG', { - vpc, - instanceType: new ec2.InstanceType('t2.micro'), - machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - minHealthyPercentage: 100, - }, - }); - }).toThrow(/Both minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: 100 and maxHealthyPercentage: undefined/); -}); + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 50, + minHealthyPercentage: 100, + }, + }); + }).toThrow(/maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); + }); -test('throws if a difference between minHealthyPercentage and maxHealthyPercentage is greater than 100', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = mockVpc(stack); + test('throws if minHealthyPercentage is greater than 100', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); - // Then - expect(() => { - new autoscaling.AutoScalingGroup(stack, 'ASG', { - vpc, - instanceType: new ec2.InstanceType('t2.micro'), - machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: 0, - }, - }); - }).toThrow(/The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got 200/); + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: 150, + }, + }); + }).toThrow(/minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); + }); + + test('throws if minHealthyPercentage is less than 0', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: -100, + }, + }); + }).toThrow(/minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); + }); + + test('throws if only minHealthyPercentage is set to -1', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: -1, + }, + }); + }).toThrow(/Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: -1 and maxHealthyPercentage: 200/); + }); + + test('throws if only maxHealthyPercentage is set to -1', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: -1, + minHealthyPercentage: 100, + }, + }); + }).toThrow(/Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: 100 and maxHealthyPercentage: -1/); + }); + + test('throws if a difference between minHealthyPercentage and maxHealthyPercentage is greater than 100', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + instanceMaintenancePolicy: { + maxHealthyPercentage: 200, + minHealthyPercentage: 0, + }, + }); + }).toThrow(/The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got 200/); + }); }); function mockSecurityGroup(stack: cdk.Stack) { From 23ef1b7c27db06aaf499a7c2e2fa443923b1d32c Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Sat, 25 Nov 2023 20:28:04 +0900 Subject: [PATCH 10/18] change the params to flat and nullable add integ --- .../integ.asg-instance-maintenance-policy.ts | 6 +- .../aws-cdk-lib/aws-autoscaling/README.md | 14 +- .../aws-autoscaling/lib/auto-scaling-group.ts | 120 ++++++++++-------- .../test/auto-scaling-group.test.ts | 118 +++++++++-------- 4 files changed, 140 insertions(+), 118 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts index 613c55f59c528..f02a0e4dc1da7 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts @@ -16,10 +16,8 @@ new autoscaling.AutoScalingGroup(stack, 'ASG', { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: 100, - }, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: 100, }); new integ.IntegTest(app, 'InstanceMaintenancePolicyTest', { diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index 8fc9c48003826..04c09fcca3fb8 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -290,7 +290,7 @@ autoScalingGroup.scaleOnSchedule('AllowDownscalingAtNight', { ### Instance Maintenance Policy -The `instanceMaintenancePolicy` allows you to configure an instance maintenance policy for +The Instance Maintenance Policy allows you to configure an instance maintenance policy for your Auto Scaling group to meet specific capacity requirements during events that cause instances to be replaced, such as an instance refresh or the health check process. @@ -300,9 +300,9 @@ when health checks indicate an impaired instance. With an instance maintenance p can make sure that Amazon EC2 Auto Scaling first launches a new instance and then waits for it to be fully ready before terminating the unhealthy instance. -An instance maintenance policy also helps you minimize any potential disruptions in cases -where multiple instances are replaced at the same time. You set the `minHealthyPercentage` -and the `maxHealthyPercentage` for the policy, and your Auto Scaling group can only +An instance maintenance policy also helps you minimize any potential disruptions in cases where +multiple instances are replaced at the same time. You set the `maintenancePolicyMinHealthPercentage` +and the `maintenancePolicyMaxHealthPercentage` for the policy, and your Auto Scaling group can only increase and decrease capacity within that minimum-maximum range when replacing instances. A larger range increases the number of instances that can be replaced at the same time. @@ -313,10 +313,8 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { vpc, instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: 100, - }, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: 100, }); ``` diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 6454ac0c0a884..53020763fa280 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -575,41 +575,6 @@ export interface LaunchTemplateOverrides { readonly weightedCapacity?: number } -/** - * Allows you to configure an instance maintenance policy for your Auto Scaling group to - * meet specific capacity requirements during events that cause instances to be replaced, such as an instance - * refresh or the health check process. - * - * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html - */ -export interface InstanceMaintenancePolicy { - /** - * Specifies the upper threshold as a percentage of the desired capacity of the Auto Scaling group. - * It represents the maximum percentage of the group that can be in service and healthy, or pending, - * to support your workload when replacing instances. - * - * Value range is 100 to 200. After it's set, a value of -1 will clear the previously set value. - * - * Both `minHealthyPercentage` and `maxHealthyPercentage` must be specified, and the difference between - * them cannot be greater than 100. A large range increases the number of instances that can be - * replaced at the same time. - */ - readonly maxHealthyPercentage: number; - - /** - * Specifies the lower threshold as a percentage of the desired capacity of the Auto Scaling group. - * It represents the minimum percentage of the group to keep in service, healthy, and ready to use - * to support your workload when replacing instances. - * - * Value range is 0 to 100. After it's set, a value of -1 will clear the previously set value. - * - * Both `minHealthyPercentage` and `maxHealthyPercentage` must be specified, and the difference between - * them cannot be greater than 100. A large range increases the number of instances that can be - * replaced at the same time. - */ - readonly minHealthyPercentage: number; -} - /** * Properties of a Fleet */ @@ -723,11 +688,40 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { readonly requireImdsv2?: boolean; /** - * An instance maintenance policy. + * Specifies the upper threshold as a percentage of the desired capacity of the Auto Scaling group. + * It represents the maximum percentage of the group that can be in service and healthy, or pending, + * to support your workload when replacing instances. + * + * Value range is 0 to 100. After it's set, both `maintenancePolicyMinHealthPercentage` and + * `maintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. + * + * Both or neither of `maintenancePolicyMinHealthPercentage` and `maintenancePolicyMaxHealthPercentage` + * must be specified, and the difference between them cannot be greater than 100. A large range increases + * the number of instances that can be replaced at the same time. + * + * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html + * + * @default - Do not provide percentage. + */ + readonly maintenancePolicyMaxHealthPercentage?: number; + + /** + * Specifies the lower threshold as a percentage of the desired capacity of the Auto Scaling group. + * It represents the minimum percentage of the group to keep in service, healthy, and ready to use + * to support your workload when replacing instances. + * + * Value range is 0 to 100. After it's set, both `maintenancePolicyMinHealthPercentage` and + * `maintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. + * + * Both or neither of `maintenancePolicyMinHealthPercentage` and `maintenancePolicyMaxHealthPercentage` + * must be specified, and the difference between them cannot be greater than 100. A large range increases + * the number of instances that can be replaced at the same time. * - * @default - no instance maintenance policy. + * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html + * + * @default - Do not provide percentage. */ - readonly instanceMaintenancePolicy?: InstanceMaintenancePolicy; + readonly maintenancePolicyMinHealthPercentage?: number; } /** @@ -1450,8 +1444,6 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements })); } - this.validateInstanceMaintenancePolicy(props.instanceMaintenancePolicy); - const { subnetIds, hasPublic } = props.vpc.selectSubnets(props.vpcSubnets); const asgProps: CfnAutoScalingGroupProps = { autoScalingGroupName: this.physicalName, @@ -1471,7 +1463,10 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements terminationPolicies: props.terminationPolicies, defaultInstanceWarmup: props.defaultInstanceWarmup?.toSeconds(), capacityRebalance: props.capacityRebalance, - instanceMaintenancePolicy: props.instanceMaintenancePolicy, + instanceMaintenancePolicy: this.renderInstanceMaintenancePolicy( + props.maintenancePolicyMaxHealthPercentage, + props.maintenancePolicyMinHealthPercentage, + ), ...this.getLaunchSettings(launchConfig, props.launchTemplate ?? launchTemplateFromConfig, props.mixedInstancesPolicy), }; @@ -1886,26 +1881,43 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements return errors; } - private validateInstanceMaintenancePolicy(policy?: InstanceMaintenancePolicy) { - if (!policy) { + private renderInstanceMaintenancePolicy( + maxHealthPercentage?: number, + minHealthPercentage?: number, + ): CfnAutoScalingGroup.InstanceMaintenancePolicyProperty | undefined { + if (maxHealthPercentage === undefined && minHealthPercentage === undefined) { return; } - const maxHealthyPercentage = policy.maxHealthyPercentage; - const minHealthyPercentage = policy.minHealthyPercentage; - - if (maxHealthyPercentage !== -1 && (maxHealthyPercentage < 100 || maxHealthyPercentage > 200)) { - throw new Error(`maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthyPercentage}`); + if ( + (maxHealthPercentage !== undefined && minHealthPercentage === undefined) + || (maxHealthPercentage === undefined && minHealthPercentage !== undefined) + ) { + throw new Error(`Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); + } + if ((maxHealthPercentage !== -1 && minHealthPercentage === -1) || (maxHealthPercentage === -1 && minHealthPercentage !== -1)) { + throw new Error(`Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); } - if (minHealthyPercentage !== -1 && (minHealthyPercentage < 0 || minHealthyPercentage > 100)) { - throw new Error(`minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthyPercentage}`); + if (maxHealthPercentage !== undefined && maxHealthPercentage !== -1 && (maxHealthPercentage < 100 || maxHealthPercentage > 200)) { + throw new Error(`maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`); } - if ((maxHealthyPercentage !== -1 && minHealthyPercentage === -1) || (maxHealthyPercentage === -1 && minHealthyPercentage !== -1)) { - throw new Error(`Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: ${minHealthyPercentage} and maxHealthyPercentage: ${maxHealthyPercentage}`); + if (minHealthPercentage !== undefined && minHealthPercentage !== -1 && (minHealthPercentage < 0 || minHealthPercentage > 100)) { + throw new Error(`maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`); } - if (maxHealthyPercentage !== -1 && minHealthyPercentage !== -1 && maxHealthyPercentage - minHealthyPercentage > 100) { - throw new Error(`The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got ${maxHealthyPercentage - minHealthyPercentage}`); + if ( + maxHealthPercentage !== undefined + && minHealthPercentage !== undefined + && maxHealthPercentage !== -1 + && minHealthPercentage !== -1 + && maxHealthPercentage - minHealthPercentage > 100 + ) { + throw new Error(`The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`); } + + return { + maxHealthyPercentage: maxHealthPercentage, + minHealthyPercentage: minHealthPercentage, + }; } } diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts index fd0276a267d2c..9c8e919fa3f77 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts @@ -2404,7 +2404,7 @@ test('requires imdsv2 when @aws-cdk/aws-autoscaling:generateLaunchTemplateInstea }); describe('InstanceMaintenancePolicy', () => { - test('InstanceMaintenancePolicy can be specified', () => { + test('maintenancePolicyMaxHealthPercentage and maintenancePolicyMinHealthPercentage can be specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2412,10 +2412,8 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: 100, - }, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: 100, }); // Then @@ -2427,7 +2425,7 @@ describe('InstanceMaintenancePolicy', () => { }); }); - test('maxHealthyPercentage and minHealthyPercentage can be set to -1', () => { + test('maintenancePolicyMaxHealthPercentage and maintenancePolicyMinHealthPercentage can be set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2435,10 +2433,8 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: -1, - minHealthyPercentage: -1, - }, + maintenancePolicyMaxHealthPercentage: -1, + maintenancePolicyMinHealthPercentage: -1, }); // Then @@ -2450,7 +2446,7 @@ describe('InstanceMaintenancePolicy', () => { }); }); - test('throws if maxHealthyPercentage is greater than 200', () => { + test('throws if maintenancePolicyMaxHealthPercentage is greater than 200', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2461,15 +2457,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 250, - minHealthyPercentage: 100, - }, + maintenancePolicyMaxHealthPercentage: 250, + maintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); + }).toThrow(/maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); }); - test('throws if maxHealthyPercentage is less than 100', () => { + test('throws if maintenancePolicyMaxHealthPercentage is less than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2480,15 +2474,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 50, - minHealthyPercentage: 100, - }, + maintenancePolicyMaxHealthPercentage: 50, + maintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); + }).toThrow(/maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); }); - test('throws if minHealthyPercentage is greater than 100', () => { + test('throws if maintenancePolicyMinHealthPercentage is greater than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2499,15 +2491,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: 150, - }, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: 150, }); - }).toThrow(/minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); + }).toThrow(/maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); }); - test('throws if minHealthyPercentage is less than 0', () => { + test('throws if maintenancePolicyMinHealthPercentage is less than 0', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2518,15 +2508,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: -100, - }, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: -100, }); - }).toThrow(/minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); + }).toThrow(/maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); }); - test('throws if only minHealthyPercentage is set to -1', () => { + test('throws if only maintenancePolicyMinHealthPercentage is set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2537,15 +2525,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: -1, - }, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: -1, }); - }).toThrow(/Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: -1 and maxHealthyPercentage: 200/); + }).toThrow(/Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: -1 and maintenancePolicyMaxHealthPercentage: 200/); }); - test('throws if only maxHealthyPercentage is set to -1', () => { + test('throws if only maintenancePolicyMaxHealthPercentage is set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2556,15 +2542,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: -1, - minHealthyPercentage: 100, - }, + maintenancePolicyMaxHealthPercentage: -1, + maintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: 100 and maxHealthyPercentage: -1/); + }).toThrow(/Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: 100 and maintenancePolicyMaxHealthPercentage: -1/); }); - test('throws if a difference between minHealthyPercentage and maxHealthyPercentage is greater than 100', () => { + test('throws if only maintenancePolicyMinHealthPercentage is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2575,12 +2559,42 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicy: { - maxHealthyPercentage: 200, - minHealthyPercentage: 0, - }, + maintenancePolicyMinHealthPercentage: 100, + }); + }).toThrow(/Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: 100 and maintenancePolicyMaxHealthPercentage: undefined/); + }); + + test('throws if only maintenancePolicyMaxHealthPercentage is specified', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + maintenancePolicyMaxHealthPercentage: 200, + }); + }).toThrow(/Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: undefined and maintenancePolicyMaxHealthPercentage: 200/); + }); + + test('throws if a difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage is greater than 100', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + + // Then + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'ASG', { + vpc, + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: 0, }); - }).toThrow(/The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got 200/); + }).toThrow(/The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got 200/); }); }); From 5eb173e65acbbed1d58e440cf151b2cbc36862ca Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Sat, 25 Nov 2023 20:38:19 +0900 Subject: [PATCH 11/18] change parameter name --- .../integ.asg-instance-maintenance-policy.ts | 4 +- .../aws-cdk-lib/aws-autoscaling/README.md | 10 +-- .../aws-autoscaling/lib/auto-scaling-group.ts | 30 +++---- .../test/auto-scaling-group.test.ts | 80 +++++++++---------- 4 files changed, 62 insertions(+), 62 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts index f02a0e4dc1da7..cdae41dce4318 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts @@ -16,8 +16,8 @@ new autoscaling.AutoScalingGroup(stack, 'ASG', { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: 100, + instanceMaintenancePolicyMaxHealthPercentage: 200, + instanceMaintenancePolicyMinHealthPercentage: 100, }); new integ.IntegTest(app, 'InstanceMaintenancePolicyTest', { diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index 04c09fcca3fb8..6c05d146d5f7f 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -301,9 +301,9 @@ can make sure that Amazon EC2 Auto Scaling first launches a new instance and the it to be fully ready before terminating the unhealthy instance. An instance maintenance policy also helps you minimize any potential disruptions in cases where -multiple instances are replaced at the same time. You set the `maintenancePolicyMinHealthPercentage` -and the `maintenancePolicyMaxHealthPercentage` for the policy, and your Auto Scaling group can only -increase and decrease capacity within that minimum-maximum range when replacing instances. +multiple instances are replaced at the same time. You set the `instanceMaintenancePolicyMinHealthPercentage` +and the `instanceMaintenancePolicyMaxHealthPercentage` for the policy, and your Auto Scaling group +can only increase and decrease capacity within that minimum-maximum range when replacing instances. A larger range increases the number of instances that can be replaced at the same time. ```ts @@ -313,8 +313,8 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { vpc, instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: 100, + instanceMaintenancePolicyMaxHealthPercentage: 200, + instanceMaintenancePolicyMinHealthPercentage: 100, }); ``` diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 53020763fa280..1913ce24572de 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -692,10 +692,10 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * It represents the maximum percentage of the group that can be in service and healthy, or pending, * to support your workload when replacing instances. * - * Value range is 0 to 100. After it's set, both `maintenancePolicyMinHealthPercentage` and - * `maintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. + * Value range is 0 to 100. After it's set, both `instanceMaintenancePolicyMinHealthPercentage` and + * `instanceMaintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. * - * Both or neither of `maintenancePolicyMinHealthPercentage` and `maintenancePolicyMaxHealthPercentage` + * Both or neither of `instanceMaintenancePolicyMinHealthPercentage` and `instanceMaintenancePolicyMaxHealthPercentage` * must be specified, and the difference between them cannot be greater than 100. A large range increases * the number of instances that can be replaced at the same time. * @@ -703,17 +703,17 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * * @default - Do not provide percentage. */ - readonly maintenancePolicyMaxHealthPercentage?: number; + readonly instanceMaintenancePolicyMaxHealthPercentage?: number; /** * Specifies the lower threshold as a percentage of the desired capacity of the Auto Scaling group. * It represents the minimum percentage of the group to keep in service, healthy, and ready to use * to support your workload when replacing instances. * - * Value range is 0 to 100. After it's set, both `maintenancePolicyMinHealthPercentage` and - * `maintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. + * Value range is 0 to 100. After it's set, both `instanceMaintenancePolicyMinHealthPercentage` and + * `instanceMaintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. * - * Both or neither of `maintenancePolicyMinHealthPercentage` and `maintenancePolicyMaxHealthPercentage` + * Both or neither of `instanceMaintenancePolicyMinHealthPercentage` and `instanceMaintenancePolicyMaxHealthPercentage` * must be specified, and the difference between them cannot be greater than 100. A large range increases * the number of instances that can be replaced at the same time. * @@ -721,7 +721,7 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * * @default - Do not provide percentage. */ - readonly maintenancePolicyMinHealthPercentage?: number; + readonly instanceMaintenancePolicyMinHealthPercentage?: number; } /** @@ -1464,8 +1464,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements defaultInstanceWarmup: props.defaultInstanceWarmup?.toSeconds(), capacityRebalance: props.capacityRebalance, instanceMaintenancePolicy: this.renderInstanceMaintenancePolicy( - props.maintenancePolicyMaxHealthPercentage, - props.maintenancePolicyMinHealthPercentage, + props.instanceMaintenancePolicyMaxHealthPercentage, + props.instanceMaintenancePolicyMinHealthPercentage, ), ...this.getLaunchSettings(launchConfig, props.launchTemplate ?? launchTemplateFromConfig, props.mixedInstancesPolicy), }; @@ -1893,16 +1893,16 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements (maxHealthPercentage !== undefined && minHealthPercentage === undefined) || (maxHealthPercentage === undefined && minHealthPercentage !== undefined) ) { - throw new Error(`Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); + throw new Error(`Both or neither of instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be specified, got instanceMaintenancePolicyMinHealthPercentage: ${minHealthPercentage} and instanceMaintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); } if ((maxHealthPercentage !== -1 && minHealthPercentage === -1) || (maxHealthPercentage === -1 && minHealthPercentage !== -1)) { - throw new Error(`Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); + throw new Error(`Both instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got instanceMaintenancePolicyMinHealthPercentage: ${minHealthPercentage} and instanceMaintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); } if (maxHealthPercentage !== undefined && maxHealthPercentage !== -1 && (maxHealthPercentage < 100 || maxHealthPercentage > 200)) { - throw new Error(`maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`); + throw new Error(`instanceMaintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`); } if (minHealthPercentage !== undefined && minHealthPercentage !== -1 && (minHealthPercentage < 0 || minHealthPercentage > 100)) { - throw new Error(`maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`); + throw new Error(`instanceMaintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`); } if ( maxHealthPercentage !== undefined @@ -1911,7 +1911,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements && minHealthPercentage !== -1 && maxHealthPercentage - minHealthPercentage > 100 ) { - throw new Error(`The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`); + throw new Error(`The difference between instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`); } return { diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts index 9c8e919fa3f77..6382ed422528c 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts @@ -2404,7 +2404,7 @@ test('requires imdsv2 when @aws-cdk/aws-autoscaling:generateLaunchTemplateInstea }); describe('InstanceMaintenancePolicy', () => { - test('maintenancePolicyMaxHealthPercentage and maintenancePolicyMinHealthPercentage can be specified', () => { + test('instanceMaintenancePolicyMaxHealthPercentage and instanceMaintenancePolicyMinHealthPercentage can be specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2412,8 +2412,8 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: 100, + instanceMaintenancePolicyMaxHealthPercentage: 200, + instanceMaintenancePolicyMinHealthPercentage: 100, }); // Then @@ -2425,7 +2425,7 @@ describe('InstanceMaintenancePolicy', () => { }); }); - test('maintenancePolicyMaxHealthPercentage and maintenancePolicyMinHealthPercentage can be set to -1', () => { + test('instanceMaintenancePolicyMaxHealthPercentage and instanceMaintenancePolicyMinHealthPercentage can be set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2433,8 +2433,8 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: -1, - maintenancePolicyMinHealthPercentage: -1, + instanceMaintenancePolicyMaxHealthPercentage: -1, + instanceMaintenancePolicyMinHealthPercentage: -1, }); // Then @@ -2446,7 +2446,7 @@ describe('InstanceMaintenancePolicy', () => { }); }); - test('throws if maintenancePolicyMaxHealthPercentage is greater than 200', () => { + test('throws if instanceMaintenancePolicyMaxHealthPercentage is greater than 200', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2457,13 +2457,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 250, - maintenancePolicyMinHealthPercentage: 100, + instanceMaintenancePolicyMaxHealthPercentage: 250, + instanceMaintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); + }).toThrow(/instanceMaintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); }); - test('throws if maintenancePolicyMaxHealthPercentage is less than 100', () => { + test('throws if instanceMaintenancePolicyMaxHealthPercentage is less than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2474,13 +2474,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 50, - maintenancePolicyMinHealthPercentage: 100, + instanceMaintenancePolicyMaxHealthPercentage: 50, + instanceMaintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); + }).toThrow(/instanceMaintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); }); - test('throws if maintenancePolicyMinHealthPercentage is greater than 100', () => { + test('throws if instanceMaintenancePolicyMinHealthPercentage is greater than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2491,13 +2491,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: 150, + instanceMaintenancePolicyMaxHealthPercentage: 200, + instanceMaintenancePolicyMinHealthPercentage: 150, }); - }).toThrow(/maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); + }).toThrow(/instanceMaintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); }); - test('throws if maintenancePolicyMinHealthPercentage is less than 0', () => { + test('throws if instanceMaintenancePolicyMinHealthPercentage is less than 0', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2508,13 +2508,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: -100, + instanceMaintenancePolicyMaxHealthPercentage: 200, + instanceMaintenancePolicyMinHealthPercentage: -100, }); - }).toThrow(/maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); + }).toThrow(/instanceMaintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); }); - test('throws if only maintenancePolicyMinHealthPercentage is set to -1', () => { + test('throws if only instanceMaintenancePolicyMinHealthPercentage is set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2525,13 +2525,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: -1, + instanceMaintenancePolicyMaxHealthPercentage: 200, + instanceMaintenancePolicyMinHealthPercentage: -1, }); - }).toThrow(/Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: -1 and maintenancePolicyMaxHealthPercentage: 200/); + }).toThrow(/Both instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got instanceMaintenancePolicyMinHealthPercentage: -1 and instanceMaintenancePolicyMaxHealthPercentage: 200/); }); - test('throws if only maintenancePolicyMaxHealthPercentage is set to -1', () => { + test('throws if only instanceMaintenancePolicyMaxHealthPercentage is set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2542,13 +2542,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: -1, - maintenancePolicyMinHealthPercentage: 100, + instanceMaintenancePolicyMaxHealthPercentage: -1, + instanceMaintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: 100 and maintenancePolicyMaxHealthPercentage: -1/); + }).toThrow(/Both instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got instanceMaintenancePolicyMinHealthPercentage: 100 and instanceMaintenancePolicyMaxHealthPercentage: -1/); }); - test('throws if only maintenancePolicyMinHealthPercentage is specified', () => { + test('throws if only instanceMaintenancePolicyMinHealthPercentage is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2559,12 +2559,12 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMinHealthPercentage: 100, + instanceMaintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: 100 and maintenancePolicyMaxHealthPercentage: undefined/); + }).toThrow(/Both or neither of instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be specified, got instanceMaintenancePolicyMinHealthPercentage: 100 and instanceMaintenancePolicyMaxHealthPercentage: undefined/); }); - test('throws if only maintenancePolicyMaxHealthPercentage is specified', () => { + test('throws if only instanceMaintenancePolicyMaxHealthPercentage is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2575,12 +2575,12 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, + instanceMaintenancePolicyMaxHealthPercentage: 200, }); - }).toThrow(/Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: undefined and maintenancePolicyMaxHealthPercentage: 200/); + }).toThrow(/Both or neither of instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be specified, got instanceMaintenancePolicyMinHealthPercentage: undefined and instanceMaintenancePolicyMaxHealthPercentage: 200/); }); - test('throws if a difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage is greater than 100', () => { + test('throws if a difference between instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage is greater than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2591,10 +2591,10 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: 0, + instanceMaintenancePolicyMaxHealthPercentage: 200, + instanceMaintenancePolicyMinHealthPercentage: 0, }); - }).toThrow(/The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got 200/); + }).toThrow(/The difference between instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage cannot be greater than 100, got 200/); }); }); From 42b82e5d22e07cfa3b98027079b68c89c2a0e513 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Sat, 25 Nov 2023 20:41:13 +0900 Subject: [PATCH 12/18] change README --- packages/aws-cdk-lib/aws-autoscaling/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index 6c05d146d5f7f..9f54f8379e63d 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -290,7 +290,7 @@ autoScalingGroup.scaleOnSchedule('AllowDownscalingAtNight', { ### Instance Maintenance Policy -The Instance Maintenance Policy allows you to configure an instance maintenance policy for +The instance maintenance policy allows you to configure an instance maintenance policy for your Auto Scaling group to meet specific capacity requirements during events that cause instances to be replaced, such as an instance refresh or the health check process. From 29da64a27273299ef3e5166a40fae1bebae71af3 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Mon, 27 Nov 2023 20:04:08 +0900 Subject: [PATCH 13/18] Revert "change parameter name" This reverts commit 5eb173e65acbbed1d58e440cf151b2cbc36862ca. --- .../integ.asg-instance-maintenance-policy.ts | 4 +- .../aws-cdk-lib/aws-autoscaling/README.md | 10 +-- .../aws-autoscaling/lib/auto-scaling-group.ts | 30 +++---- .../test/auto-scaling-group.test.ts | 80 +++++++++---------- 4 files changed, 62 insertions(+), 62 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts index cdae41dce4318..f02a0e4dc1da7 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts @@ -16,8 +16,8 @@ new autoscaling.AutoScalingGroup(stack, 'ASG', { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }), - instanceMaintenancePolicyMaxHealthPercentage: 200, - instanceMaintenancePolicyMinHealthPercentage: 100, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: 100, }); new integ.IntegTest(app, 'InstanceMaintenancePolicyTest', { diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index 9f54f8379e63d..594768a4f4a95 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -301,9 +301,9 @@ can make sure that Amazon EC2 Auto Scaling first launches a new instance and the it to be fully ready before terminating the unhealthy instance. An instance maintenance policy also helps you minimize any potential disruptions in cases where -multiple instances are replaced at the same time. You set the `instanceMaintenancePolicyMinHealthPercentage` -and the `instanceMaintenancePolicyMaxHealthPercentage` for the policy, and your Auto Scaling group -can only increase and decrease capacity within that minimum-maximum range when replacing instances. +multiple instances are replaced at the same time. You set the `maintenancePolicyMinHealthPercentage` +and the `maintenancePolicyMaxHealthPercentage` for the policy, and your Auto Scaling group can only +increase and decrease capacity within that minimum-maximum range when replacing instances. A larger range increases the number of instances that can be replaced at the same time. ```ts @@ -313,8 +313,8 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { vpc, instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: 200, - instanceMaintenancePolicyMinHealthPercentage: 100, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: 100, }); ``` diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 1913ce24572de..53020763fa280 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -692,10 +692,10 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * It represents the maximum percentage of the group that can be in service and healthy, or pending, * to support your workload when replacing instances. * - * Value range is 0 to 100. After it's set, both `instanceMaintenancePolicyMinHealthPercentage` and - * `instanceMaintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. + * Value range is 0 to 100. After it's set, both `maintenancePolicyMinHealthPercentage` and + * `maintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. * - * Both or neither of `instanceMaintenancePolicyMinHealthPercentage` and `instanceMaintenancePolicyMaxHealthPercentage` + * Both or neither of `maintenancePolicyMinHealthPercentage` and `maintenancePolicyMaxHealthPercentage` * must be specified, and the difference between them cannot be greater than 100. A large range increases * the number of instances that can be replaced at the same time. * @@ -703,17 +703,17 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * * @default - Do not provide percentage. */ - readonly instanceMaintenancePolicyMaxHealthPercentage?: number; + readonly maintenancePolicyMaxHealthPercentage?: number; /** * Specifies the lower threshold as a percentage of the desired capacity of the Auto Scaling group. * It represents the minimum percentage of the group to keep in service, healthy, and ready to use * to support your workload when replacing instances. * - * Value range is 0 to 100. After it's set, both `instanceMaintenancePolicyMinHealthPercentage` and - * `instanceMaintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. + * Value range is 0 to 100. After it's set, both `maintenancePolicyMinHealthPercentage` and + * `maintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. * - * Both or neither of `instanceMaintenancePolicyMinHealthPercentage` and `instanceMaintenancePolicyMaxHealthPercentage` + * Both or neither of `maintenancePolicyMinHealthPercentage` and `maintenancePolicyMaxHealthPercentage` * must be specified, and the difference between them cannot be greater than 100. A large range increases * the number of instances that can be replaced at the same time. * @@ -721,7 +721,7 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * * @default - Do not provide percentage. */ - readonly instanceMaintenancePolicyMinHealthPercentage?: number; + readonly maintenancePolicyMinHealthPercentage?: number; } /** @@ -1464,8 +1464,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements defaultInstanceWarmup: props.defaultInstanceWarmup?.toSeconds(), capacityRebalance: props.capacityRebalance, instanceMaintenancePolicy: this.renderInstanceMaintenancePolicy( - props.instanceMaintenancePolicyMaxHealthPercentage, - props.instanceMaintenancePolicyMinHealthPercentage, + props.maintenancePolicyMaxHealthPercentage, + props.maintenancePolicyMinHealthPercentage, ), ...this.getLaunchSettings(launchConfig, props.launchTemplate ?? launchTemplateFromConfig, props.mixedInstancesPolicy), }; @@ -1893,16 +1893,16 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements (maxHealthPercentage !== undefined && minHealthPercentage === undefined) || (maxHealthPercentage === undefined && minHealthPercentage !== undefined) ) { - throw new Error(`Both or neither of instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be specified, got instanceMaintenancePolicyMinHealthPercentage: ${minHealthPercentage} and instanceMaintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); + throw new Error(`Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); } if ((maxHealthPercentage !== -1 && minHealthPercentage === -1) || (maxHealthPercentage === -1 && minHealthPercentage !== -1)) { - throw new Error(`Both instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got instanceMaintenancePolicyMinHealthPercentage: ${minHealthPercentage} and instanceMaintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); + throw new Error(`Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); } if (maxHealthPercentage !== undefined && maxHealthPercentage !== -1 && (maxHealthPercentage < 100 || maxHealthPercentage > 200)) { - throw new Error(`instanceMaintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`); + throw new Error(`maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`); } if (minHealthPercentage !== undefined && minHealthPercentage !== -1 && (minHealthPercentage < 0 || minHealthPercentage > 100)) { - throw new Error(`instanceMaintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`); + throw new Error(`maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`); } if ( maxHealthPercentage !== undefined @@ -1911,7 +1911,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements && minHealthPercentage !== -1 && maxHealthPercentage - minHealthPercentage > 100 ) { - throw new Error(`The difference between instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`); + throw new Error(`The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`); } return { diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts index 6382ed422528c..9c8e919fa3f77 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts @@ -2404,7 +2404,7 @@ test('requires imdsv2 when @aws-cdk/aws-autoscaling:generateLaunchTemplateInstea }); describe('InstanceMaintenancePolicy', () => { - test('instanceMaintenancePolicyMaxHealthPercentage and instanceMaintenancePolicyMinHealthPercentage can be specified', () => { + test('maintenancePolicyMaxHealthPercentage and maintenancePolicyMinHealthPercentage can be specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2412,8 +2412,8 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: 200, - instanceMaintenancePolicyMinHealthPercentage: 100, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: 100, }); // Then @@ -2425,7 +2425,7 @@ describe('InstanceMaintenancePolicy', () => { }); }); - test('instanceMaintenancePolicyMaxHealthPercentage and instanceMaintenancePolicyMinHealthPercentage can be set to -1', () => { + test('maintenancePolicyMaxHealthPercentage and maintenancePolicyMinHealthPercentage can be set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2433,8 +2433,8 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: -1, - instanceMaintenancePolicyMinHealthPercentage: -1, + maintenancePolicyMaxHealthPercentage: -1, + maintenancePolicyMinHealthPercentage: -1, }); // Then @@ -2446,7 +2446,7 @@ describe('InstanceMaintenancePolicy', () => { }); }); - test('throws if instanceMaintenancePolicyMaxHealthPercentage is greater than 200', () => { + test('throws if maintenancePolicyMaxHealthPercentage is greater than 200', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2457,13 +2457,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: 250, - instanceMaintenancePolicyMinHealthPercentage: 100, + maintenancePolicyMaxHealthPercentage: 250, + maintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/instanceMaintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); + }).toThrow(/maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); }); - test('throws if instanceMaintenancePolicyMaxHealthPercentage is less than 100', () => { + test('throws if maintenancePolicyMaxHealthPercentage is less than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2474,13 +2474,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: 50, - instanceMaintenancePolicyMinHealthPercentage: 100, + maintenancePolicyMaxHealthPercentage: 50, + maintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/instanceMaintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); + }).toThrow(/maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); }); - test('throws if instanceMaintenancePolicyMinHealthPercentage is greater than 100', () => { + test('throws if maintenancePolicyMinHealthPercentage is greater than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2491,13 +2491,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: 200, - instanceMaintenancePolicyMinHealthPercentage: 150, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: 150, }); - }).toThrow(/instanceMaintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); + }).toThrow(/maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); }); - test('throws if instanceMaintenancePolicyMinHealthPercentage is less than 0', () => { + test('throws if maintenancePolicyMinHealthPercentage is less than 0', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2508,13 +2508,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: 200, - instanceMaintenancePolicyMinHealthPercentage: -100, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: -100, }); - }).toThrow(/instanceMaintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); + }).toThrow(/maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); }); - test('throws if only instanceMaintenancePolicyMinHealthPercentage is set to -1', () => { + test('throws if only maintenancePolicyMinHealthPercentage is set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2525,13 +2525,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: 200, - instanceMaintenancePolicyMinHealthPercentage: -1, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: -1, }); - }).toThrow(/Both instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got instanceMaintenancePolicyMinHealthPercentage: -1 and instanceMaintenancePolicyMaxHealthPercentage: 200/); + }).toThrow(/Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: -1 and maintenancePolicyMaxHealthPercentage: 200/); }); - test('throws if only instanceMaintenancePolicyMaxHealthPercentage is set to -1', () => { + test('throws if only maintenancePolicyMaxHealthPercentage is set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2542,13 +2542,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: -1, - instanceMaintenancePolicyMinHealthPercentage: 100, + maintenancePolicyMaxHealthPercentage: -1, + maintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/Both instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got instanceMaintenancePolicyMinHealthPercentage: 100 and instanceMaintenancePolicyMaxHealthPercentage: -1/); + }).toThrow(/Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: 100 and maintenancePolicyMaxHealthPercentage: -1/); }); - test('throws if only instanceMaintenancePolicyMinHealthPercentage is specified', () => { + test('throws if only maintenancePolicyMinHealthPercentage is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2559,12 +2559,12 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMinHealthPercentage: 100, + maintenancePolicyMinHealthPercentage: 100, }); - }).toThrow(/Both or neither of instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be specified, got instanceMaintenancePolicyMinHealthPercentage: 100 and instanceMaintenancePolicyMaxHealthPercentage: undefined/); + }).toThrow(/Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: 100 and maintenancePolicyMaxHealthPercentage: undefined/); }); - test('throws if only instanceMaintenancePolicyMaxHealthPercentage is specified', () => { + test('throws if only maintenancePolicyMaxHealthPercentage is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2575,12 +2575,12 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMaxHealthPercentage: 200, }); - }).toThrow(/Both or neither of instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage must be specified, got instanceMaintenancePolicyMinHealthPercentage: undefined and instanceMaintenancePolicyMaxHealthPercentage: 200/); + }).toThrow(/Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: undefined and maintenancePolicyMaxHealthPercentage: 200/); }); - test('throws if a difference between instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage is greater than 100', () => { + test('throws if a difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage is greater than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2591,10 +2591,10 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - instanceMaintenancePolicyMaxHealthPercentage: 200, - instanceMaintenancePolicyMinHealthPercentage: 0, + maintenancePolicyMaxHealthPercentage: 200, + maintenancePolicyMinHealthPercentage: 0, }); - }).toThrow(/The difference between instanceMaintenancePolicyMinHealthPercentage and instanceMaintenancePolicyMaxHealthPercentage cannot be greater than 100, got 200/); + }).toThrow(/The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got 200/); }); }); From 7abed93f08a475511f22d087edf19b967ceb17d5 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Mon, 27 Nov 2023 20:05:47 +0900 Subject: [PATCH 14/18] change default --- .../aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 53020763fa280..9f47a4140cc69 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -701,7 +701,7 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html * - * @default - Do not provide percentage. + * @default - No instance maintenance policy. */ readonly maintenancePolicyMaxHealthPercentage?: number; @@ -719,7 +719,7 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html * - * @default - Do not provide percentage. + * @default - No instance maintenance policy. */ readonly maintenancePolicyMinHealthPercentage?: number; } From 31cdf6833572214c76f2df9c6479d0e686e94fda Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Mon, 27 Nov 2023 22:24:10 +0900 Subject: [PATCH 15/18] refactor method --- .../aws-autoscaling/lib/auto-scaling-group.ts | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 9f47a4140cc69..1725d0e9d4b00 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -1885,35 +1885,28 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements maxHealthPercentage?: number, minHealthPercentage?: number, ): CfnAutoScalingGroup.InstanceMaintenancePolicyProperty | undefined { - if (maxHealthPercentage === undefined && minHealthPercentage === undefined) { - return; - } - - if ( - (maxHealthPercentage !== undefined && minHealthPercentage === undefined) - || (maxHealthPercentage === undefined && minHealthPercentage !== undefined) - ) { + if (maxHealthPercentage === undefined && minHealthPercentage === undefined) return; + if (maxHealthPercentage === undefined || minHealthPercentage === undefined) { throw new Error(`Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); } - if ((maxHealthPercentage !== -1 && minHealthPercentage === -1) || (maxHealthPercentage === -1 && minHealthPercentage !== -1)) { + if (maxHealthPercentage === -1 && minHealthPercentage === -1) { + return { + maxHealthyPercentage: maxHealthPercentage, + minHealthyPercentage: minHealthPercentage, + }; + } + if (minHealthPercentage === -1 || maxHealthPercentage === -1) { throw new Error(`Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); } - if (maxHealthPercentage !== undefined && maxHealthPercentage !== -1 && (maxHealthPercentage < 100 || maxHealthPercentage > 200)) { + if (maxHealthPercentage < 100 || maxHealthPercentage > 200) { throw new Error(`maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`); } - if (minHealthPercentage !== undefined && minHealthPercentage !== -1 && (minHealthPercentage < 0 || minHealthPercentage > 100)) { + if (minHealthPercentage < 0 || minHealthPercentage > 100) { throw new Error(`maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`); } - if ( - maxHealthPercentage !== undefined - && minHealthPercentage !== undefined - && maxHealthPercentage !== -1 - && minHealthPercentage !== -1 - && maxHealthPercentage - minHealthPercentage > 100 - ) { + if (maxHealthPercentage - minHealthPercentage > 100) { throw new Error(`The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`); } - return { maxHealthyPercentage: maxHealthPercentage, minHealthyPercentage: minHealthPercentage, From 2852f7701dc49001dfe9eb12a1c2ecbacf0b25ba Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:59:35 +0900 Subject: [PATCH 16/18] change parameter names and README --- .../integ.asg-instance-maintenance-policy.ts | 4 +- .../aws-cdk-lib/aws-autoscaling/README.md | 14 ++-- .../aws-autoscaling/lib/auto-scaling-group.ts | 38 ++++----- .../test/auto-scaling-group.test.ts | 80 +++++++++---------- 4 files changed, 68 insertions(+), 68 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts index f02a0e4dc1da7..94d21974996aa 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts @@ -16,8 +16,8 @@ new autoscaling.AutoScalingGroup(stack, 'ASG', { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: 100, + maxHealthPercentage: 200, + minHealthPercentage: 100, }); new integ.IntegTest(app, 'InstanceMaintenancePolicyTest', { diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index 594768a4f4a95..d67d5825a5134 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -290,9 +290,9 @@ autoScalingGroup.scaleOnSchedule('AllowDownscalingAtNight', { ### Instance Maintenance Policy -The instance maintenance policy allows you to configure an instance maintenance policy for -your Auto Scaling group to meet specific capacity requirements during events that cause -instances to be replaced, such as an instance refresh or the health check process. +You can configure an instance maintenance policy for your Auto Scaling group to +meet specific capacity requirements during events that cause instances to be replaced, +such as an instance refresh or the health check process. For example, suppose you have an Auto Scaling group that has a small number of instances. You want to avoid the potential disruptions from terminating and then replacing an instance @@ -301,8 +301,8 @@ can make sure that Amazon EC2 Auto Scaling first launches a new instance and the it to be fully ready before terminating the unhealthy instance. An instance maintenance policy also helps you minimize any potential disruptions in cases where -multiple instances are replaced at the same time. You set the `maintenancePolicyMinHealthPercentage` -and the `maintenancePolicyMaxHealthPercentage` for the policy, and your Auto Scaling group can only +multiple instances are replaced at the same time. You set the `minHealthPercentage` +and the `maxHealthPercentage` for the policy, and your Auto Scaling group can only increase and decrease capacity within that minimum-maximum range when replacing instances. A larger range increases the number of instances that can be replaced at the same time. @@ -313,8 +313,8 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { vpc, instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: 100, + maxHealthPercentage: 200, + minHealthPercentage: 100, }); ``` diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index 1725d0e9d4b00..498d28804231c 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -692,36 +692,36 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * It represents the maximum percentage of the group that can be in service and healthy, or pending, * to support your workload when replacing instances. * - * Value range is 0 to 100. After it's set, both `maintenancePolicyMinHealthPercentage` and - * `maintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. + * Value range is 0 to 100. After it's set, both `minHealthPercentage` and `maxHealthPercentage` to + * -1 will clear the previously set value. * - * Both or neither of `maintenancePolicyMinHealthPercentage` and `maintenancePolicyMaxHealthPercentage` - * must be specified, and the difference between them cannot be greater than 100. A large range increases - * the number of instances that can be replaced at the same time. + * Both or neither of `minHealthPercentage` and `maxHealthPercentage` must be specified, and the + * difference between them cannot be greater than 100. A large range increases the number of + * instances that can be replaced at the same time. * * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html * * @default - No instance maintenance policy. */ - readonly maintenancePolicyMaxHealthPercentage?: number; + readonly maxHealthPercentage?: number; /** * Specifies the lower threshold as a percentage of the desired capacity of the Auto Scaling group. * It represents the minimum percentage of the group to keep in service, healthy, and ready to use * to support your workload when replacing instances. * - * Value range is 0 to 100. After it's set, both `maintenancePolicyMinHealthPercentage` and - * `maintenancePolicyMaxHealthPercentage` to -1 will clear the previously set value. + * Value range is 0 to 100. After it's set, both `minHealthPercentage` and `maxHealthPercentage` to + * -1 will clear the previously set value. * - * Both or neither of `maintenancePolicyMinHealthPercentage` and `maintenancePolicyMaxHealthPercentage` - * must be specified, and the difference between them cannot be greater than 100. A large range increases - * the number of instances that can be replaced at the same time. + * Both or neither of `minHealthPercentage` and `maxHealthPercentage` must be specified, and the + * difference between them cannot be greater than 100. A large range increases the number of + * instances that can be replaced at the same time. * * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html * * @default - No instance maintenance policy. */ - readonly maintenancePolicyMinHealthPercentage?: number; + readonly minHealthPercentage?: number; } /** @@ -1464,8 +1464,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements defaultInstanceWarmup: props.defaultInstanceWarmup?.toSeconds(), capacityRebalance: props.capacityRebalance, instanceMaintenancePolicy: this.renderInstanceMaintenancePolicy( - props.maintenancePolicyMaxHealthPercentage, - props.maintenancePolicyMinHealthPercentage, + props.maxHealthPercentage, + props.minHealthPercentage, ), ...this.getLaunchSettings(launchConfig, props.launchTemplate ?? launchTemplateFromConfig, props.mixedInstancesPolicy), }; @@ -1887,7 +1887,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements ): CfnAutoScalingGroup.InstanceMaintenancePolicyProperty | undefined { if (maxHealthPercentage === undefined && minHealthPercentage === undefined) return; if (maxHealthPercentage === undefined || minHealthPercentage === undefined) { - throw new Error(`Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); + throw new Error(`Both or neither of minHealthPercentage and maxHealthPercentage must be specified, got minHealthPercentage: ${minHealthPercentage} and maxHealthPercentage: ${maxHealthPercentage}`); } if (maxHealthPercentage === -1 && minHealthPercentage === -1) { return { @@ -1896,16 +1896,16 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements }; } if (minHealthPercentage === -1 || maxHealthPercentage === -1) { - throw new Error(`Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); + throw new Error(`Both minHealthPercentage and maxHealthPercentage must be -1 to clear the previously set value, got minHealthPercentage: ${minHealthPercentage} and maxHealthPercentage: ${maxHealthPercentage}`); } if (maxHealthPercentage < 100 || maxHealthPercentage > 200) { - throw new Error(`maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`); + throw new Error(`maxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`); } if (minHealthPercentage < 0 || minHealthPercentage > 100) { - throw new Error(`maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`); + throw new Error(`minHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`); } if (maxHealthPercentage - minHealthPercentage > 100) { - throw new Error(`The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`); + throw new Error(`The difference between minHealthPercentage and maxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`); } return { maxHealthyPercentage: maxHealthPercentage, diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts index 9c8e919fa3f77..055c5a502a518 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts @@ -2404,7 +2404,7 @@ test('requires imdsv2 when @aws-cdk/aws-autoscaling:generateLaunchTemplateInstea }); describe('InstanceMaintenancePolicy', () => { - test('maintenancePolicyMaxHealthPercentage and maintenancePolicyMinHealthPercentage can be specified', () => { + test('maxHealthPercentage and minHealthPercentage can be specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2412,8 +2412,8 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: 100, + maxHealthPercentage: 200, + minHealthPercentage: 100, }); // Then @@ -2425,7 +2425,7 @@ describe('InstanceMaintenancePolicy', () => { }); }); - test('maintenancePolicyMaxHealthPercentage and maintenancePolicyMinHealthPercentage can be set to -1', () => { + test('maxHealthPercentage and minHealthPercentage can be set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2433,8 +2433,8 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: -1, - maintenancePolicyMinHealthPercentage: -1, + maxHealthPercentage: -1, + minHealthPercentage: -1, }); // Then @@ -2446,7 +2446,7 @@ describe('InstanceMaintenancePolicy', () => { }); }); - test('throws if maintenancePolicyMaxHealthPercentage is greater than 200', () => { + test('throws if maxHealthPercentage is greater than 200', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2457,13 +2457,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 250, - maintenancePolicyMinHealthPercentage: 100, + maxHealthPercentage: 250, + minHealthPercentage: 100, }); - }).toThrow(/maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); + }).toThrow(/maxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); }); - test('throws if maintenancePolicyMaxHealthPercentage is less than 100', () => { + test('throws if maxHealthPercentage is less than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2474,13 +2474,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 50, - maintenancePolicyMinHealthPercentage: 100, + maxHealthPercentage: 50, + minHealthPercentage: 100, }); - }).toThrow(/maintenancePolicyMaxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); + }).toThrow(/maxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); }); - test('throws if maintenancePolicyMinHealthPercentage is greater than 100', () => { + test('throws if minHealthPercentage is greater than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2491,13 +2491,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: 150, + maxHealthPercentage: 200, + minHealthPercentage: 150, }); - }).toThrow(/maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); + }).toThrow(/minHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); }); - test('throws if maintenancePolicyMinHealthPercentage is less than 0', () => { + test('throws if minHealthPercentage is less than 0', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2508,13 +2508,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: -100, + maxHealthPercentage: 200, + minHealthPercentage: -100, }); - }).toThrow(/maintenancePolicyMinHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); + }).toThrow(/minHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); }); - test('throws if only maintenancePolicyMinHealthPercentage is set to -1', () => { + test('throws if only minHealthPercentage is set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2525,13 +2525,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: -1, + maxHealthPercentage: 200, + minHealthPercentage: -1, }); - }).toThrow(/Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: -1 and maintenancePolicyMaxHealthPercentage: 200/); + }).toThrow(/Both minHealthPercentage and maxHealthPercentage must be -1 to clear the previously set value, got minHealthPercentage: -1 and maxHealthPercentage: 200/); }); - test('throws if only maintenancePolicyMaxHealthPercentage is set to -1', () => { + test('throws if only maxHealthPercentage is set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2542,13 +2542,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: -1, - maintenancePolicyMinHealthPercentage: 100, + maxHealthPercentage: -1, + minHealthPercentage: 100, }); - }).toThrow(/Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: 100 and maintenancePolicyMaxHealthPercentage: -1/); + }).toThrow(/Both minHealthPercentage and maxHealthPercentage must be -1 to clear the previously set value, got minHealthPercentage: 100 and maxHealthPercentage: -1/); }); - test('throws if only maintenancePolicyMinHealthPercentage is specified', () => { + test('throws if only minHealthPercentage is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2559,12 +2559,12 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMinHealthPercentage: 100, + minHealthPercentage: 100, }); - }).toThrow(/Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: 100 and maintenancePolicyMaxHealthPercentage: undefined/); + }).toThrow(/Both or neither of minHealthPercentage and maxHealthPercentage must be specified, got minHealthPercentage: 100 and maxHealthPercentage: undefined/); }); - test('throws if only maintenancePolicyMaxHealthPercentage is specified', () => { + test('throws if only maxHealthPercentage is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2575,12 +2575,12 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, + maxHealthPercentage: 200, }); - }).toThrow(/Both or neither of maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be specified, got maintenancePolicyMinHealthPercentage: undefined and maintenancePolicyMaxHealthPercentage: 200/); + }).toThrow(/Both or neither of minHealthPercentage and maxHealthPercentage must be specified, got minHealthPercentage: undefined and maxHealthPercentage: 200/); }); - test('throws if a difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage is greater than 100', () => { + test('throws if a difference between minHealthPercentage and maxHealthPercentage is greater than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2591,10 +2591,10 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maintenancePolicyMaxHealthPercentage: 200, - maintenancePolicyMinHealthPercentage: 0, + maxHealthPercentage: 200, + minHealthPercentage: 0, }); - }).toThrow(/The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got 200/); + }).toThrow(/The difference between minHealthPercentage and maxHealthPercentage cannot be greater than 100, got 200/); }); }); From 43d5c02f443ab903cd635247c046b0dcd2cd83c0 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Thu, 21 Dec 2023 14:42:10 +0900 Subject: [PATCH 17/18] improve renderInstanceMaintenancePolicy and change param names to maxHealthyPercentage and minHealthyPercentage --- .../integ.asg-instance-maintenance-policy.ts | 4 +- .../aws-cdk-lib/aws-autoscaling/README.md | 8 +- .../aws-autoscaling/lib/auto-scaling-group.ts | 52 ++++++------ .../test/auto-scaling-group.test.ts | 80 +++++++++---------- 4 files changed, 69 insertions(+), 75 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts index 94d21974996aa..fd0195c35d326 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-instance-maintenance-policy.ts @@ -16,8 +16,8 @@ new autoscaling.AutoScalingGroup(stack, 'ASG', { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }), - maxHealthPercentage: 200, - minHealthPercentage: 100, + maxHealthyPercentage: 200, + minHealthyPercentage: 100, }); new integ.IntegTest(app, 'InstanceMaintenancePolicyTest', { diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index d67d5825a5134..91bac6fc22c91 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -301,8 +301,8 @@ can make sure that Amazon EC2 Auto Scaling first launches a new instance and the it to be fully ready before terminating the unhealthy instance. An instance maintenance policy also helps you minimize any potential disruptions in cases where -multiple instances are replaced at the same time. You set the `minHealthPercentage` -and the `maxHealthPercentage` for the policy, and your Auto Scaling group can only +multiple instances are replaced at the same time. You set the `minHealthyPercentage` +and the `maxHealthyPercentage` for the policy, and your Auto Scaling group can only increase and decrease capacity within that minimum-maximum range when replacing instances. A larger range increases the number of instances that can be replaced at the same time. @@ -313,8 +313,8 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { vpc, instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: 200, - minHealthPercentage: 100, + maxHealthyPercentage: 200, + minHealthyPercentage: 100, }); ``` diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index c4af076ada2e7..bd69ef0eeceb0 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -701,10 +701,10 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * It represents the maximum percentage of the group that can be in service and healthy, or pending, * to support your workload when replacing instances. * - * Value range is 0 to 100. After it's set, both `minHealthPercentage` and `maxHealthPercentage` to + * Value range is 0 to 100. After it's set, both `minHealthyPercentage` and `maxHealthyPercentage` to * -1 will clear the previously set value. * - * Both or neither of `minHealthPercentage` and `maxHealthPercentage` must be specified, and the + * Both or neither of `minHealthyPercentage` and `maxHealthyPercentage` must be specified, and the * difference between them cannot be greater than 100. A large range increases the number of * instances that can be replaced at the same time. * @@ -712,17 +712,17 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * * @default - No instance maintenance policy. */ - readonly maxHealthPercentage?: number; + readonly maxHealthyPercentage?: number; /** * Specifies the lower threshold as a percentage of the desired capacity of the Auto Scaling group. * It represents the minimum percentage of the group to keep in service, healthy, and ready to use * to support your workload when replacing instances. * - * Value range is 0 to 100. After it's set, both `minHealthPercentage` and `maxHealthPercentage` to + * Value range is 0 to 100. After it's set, both `minHealthyPercentage` and `maxHealthyPercentage` to * -1 will clear the previously set value. * - * Both or neither of `minHealthPercentage` and `maxHealthPercentage` must be specified, and the + * Both or neither of `minHealthyPercentage` and `maxHealthyPercentage` must be specified, and the * difference between them cannot be greater than 100. A large range increases the number of * instances that can be replaced at the same time. * @@ -730,7 +730,7 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps { * * @default - No instance maintenance policy. */ - readonly minHealthPercentage?: number; + readonly minHealthyPercentage?: number; } /** @@ -1473,8 +1473,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements defaultInstanceWarmup: props.defaultInstanceWarmup?.toSeconds(), capacityRebalance: props.capacityRebalance, instanceMaintenancePolicy: this.renderInstanceMaintenancePolicy( - props.maxHealthPercentage, - props.minHealthPercentage, + props.maxHealthyPercentage, + props.minHealthyPercentage, ), ...this.getLaunchSettings(launchConfig, props.launchTemplate ?? launchTemplateFromConfig, props.mixedInstancesPolicy), }; @@ -1891,34 +1891,28 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements } private renderInstanceMaintenancePolicy( - maxHealthPercentage?: number, - minHealthPercentage?: number, + maxHealthyPercentage?: number, + minHealthyPercentage?: number, ): CfnAutoScalingGroup.InstanceMaintenancePolicyProperty | undefined { - if (maxHealthPercentage === undefined && minHealthPercentage === undefined) return; - if (maxHealthPercentage === undefined || minHealthPercentage === undefined) { - throw new Error(`Both or neither of minHealthPercentage and maxHealthPercentage must be specified, got minHealthPercentage: ${minHealthPercentage} and maxHealthPercentage: ${maxHealthPercentage}`); + if (maxHealthyPercentage === undefined && minHealthyPercentage === undefined) return; + if (maxHealthyPercentage === undefined || minHealthyPercentage === undefined) { + throw new Error(`Both or neither of minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: ${minHealthyPercentage} and maxHealthyPercentage: ${maxHealthyPercentage}`); } - if (maxHealthPercentage === -1 && minHealthPercentage === -1) { - return { - maxHealthyPercentage: maxHealthPercentage, - minHealthyPercentage: minHealthPercentage, - }; - } - if (minHealthPercentage === -1 || maxHealthPercentage === -1) { - throw new Error(`Both minHealthPercentage and maxHealthPercentage must be -1 to clear the previously set value, got minHealthPercentage: ${minHealthPercentage} and maxHealthPercentage: ${maxHealthPercentage}`); + if ((minHealthyPercentage === -1 || maxHealthyPercentage === -1) && minHealthyPercentage !== maxHealthyPercentage) { + throw new Error(`Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: ${minHealthyPercentage} and maxHealthyPercentage: ${maxHealthyPercentage}`); } - if (maxHealthPercentage < 100 || maxHealthPercentage > 200) { - throw new Error(`maxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`); + if (maxHealthyPercentage !== -1 && (maxHealthyPercentage < 100 || maxHealthyPercentage > 200)) { + throw new Error(`maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthyPercentage}`); } - if (minHealthPercentage < 0 || minHealthPercentage > 100) { - throw new Error(`minHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`); + if (minHealthyPercentage !== -1 && (minHealthyPercentage < 0 || minHealthyPercentage > 100)) { + throw new Error(`minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthyPercentage}`); } - if (maxHealthPercentage - minHealthPercentage > 100) { - throw new Error(`The difference between minHealthPercentage and maxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`); + if (maxHealthyPercentage - minHealthyPercentage > 100) { + throw new Error(`The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got ${maxHealthyPercentage - minHealthyPercentage}`); } return { - maxHealthyPercentage: maxHealthPercentage, - minHealthyPercentage: minHealthPercentage, + maxHealthyPercentage, + minHealthyPercentage, }; } } diff --git a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts index 11af75b37b370..1ea4e5665ba25 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts @@ -2441,7 +2441,7 @@ test('requires imdsv2 when @aws-cdk/aws-autoscaling:generateLaunchTemplateInstea }); describe('InstanceMaintenancePolicy', () => { - test('maxHealthPercentage and minHealthPercentage can be specified', () => { + test('maxHealthyPercentage and minHealthyPercentage can be specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2449,8 +2449,8 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: 200, - minHealthPercentage: 100, + maxHealthyPercentage: 200, + minHealthyPercentage: 100, }); // Then @@ -2462,7 +2462,7 @@ describe('InstanceMaintenancePolicy', () => { }); }); - test('maxHealthPercentage and minHealthPercentage can be set to -1', () => { + test('maxHealthyPercentage and minHealthyPercentage can be set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2470,8 +2470,8 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: -1, - minHealthPercentage: -1, + maxHealthyPercentage: -1, + minHealthyPercentage: -1, }); // Then @@ -2483,7 +2483,7 @@ describe('InstanceMaintenancePolicy', () => { }); }); - test('throws if maxHealthPercentage is greater than 200', () => { + test('throws if maxHealthyPercentage is greater than 200', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2494,13 +2494,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: 250, - minHealthPercentage: 100, + maxHealthyPercentage: 250, + minHealthyPercentage: 100, }); - }).toThrow(/maxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); + }).toThrow(/maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got 250/); }); - test('throws if maxHealthPercentage is less than 100', () => { + test('throws if maxHealthyPercentage is less than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2511,13 +2511,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: 50, - minHealthPercentage: 100, + maxHealthyPercentage: 50, + minHealthyPercentage: 100, }); - }).toThrow(/maxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); + }).toThrow(/maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got 50/); }); - test('throws if minHealthPercentage is greater than 100', () => { + test('throws if minHealthyPercentage is greater than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2528,13 +2528,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: 200, - minHealthPercentage: 150, + maxHealthyPercentage: 200, + minHealthyPercentage: 150, }); - }).toThrow(/minHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); + }).toThrow(/minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got 150/); }); - test('throws if minHealthPercentage is less than 0', () => { + test('throws if minHealthyPercentage is less than 0', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2545,13 +2545,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: 200, - minHealthPercentage: -100, + maxHealthyPercentage: 200, + minHealthyPercentage: -100, }); - }).toThrow(/minHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); + }).toThrow(/minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got -100/); }); - test('throws if only minHealthPercentage is set to -1', () => { + test('throws if only minHealthyPercentage is set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2562,13 +2562,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: 200, - minHealthPercentage: -1, + maxHealthyPercentage: 200, + minHealthyPercentage: -1, }); - }).toThrow(/Both minHealthPercentage and maxHealthPercentage must be -1 to clear the previously set value, got minHealthPercentage: -1 and maxHealthPercentage: 200/); + }).toThrow(/Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: -1 and maxHealthyPercentage: 200/); }); - test('throws if only maxHealthPercentage is set to -1', () => { + test('throws if only maxHealthyPercentage is set to -1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2579,13 +2579,13 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: -1, - minHealthPercentage: 100, + maxHealthyPercentage: -1, + minHealthyPercentage: 100, }); - }).toThrow(/Both minHealthPercentage and maxHealthPercentage must be -1 to clear the previously set value, got minHealthPercentage: 100 and maxHealthPercentage: -1/); + }).toThrow(/Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: 100 and maxHealthyPercentage: -1/); }); - test('throws if only minHealthPercentage is specified', () => { + test('throws if only minHealthyPercentage is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2596,12 +2596,12 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - minHealthPercentage: 100, + minHealthyPercentage: 100, }); - }).toThrow(/Both or neither of minHealthPercentage and maxHealthPercentage must be specified, got minHealthPercentage: 100 and maxHealthPercentage: undefined/); + }).toThrow(/Both or neither of minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: 100 and maxHealthyPercentage: undefined/); }); - test('throws if only maxHealthPercentage is specified', () => { + test('throws if only maxHealthyPercentage is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2612,12 +2612,12 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: 200, + maxHealthyPercentage: 200, }); - }).toThrow(/Both or neither of minHealthPercentage and maxHealthPercentage must be specified, got minHealthPercentage: undefined and maxHealthPercentage: 200/); + }).toThrow(/Both or neither of minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: undefined and maxHealthyPercentage: 200/); }); - test('throws if a difference between minHealthPercentage and maxHealthPercentage is greater than 100', () => { + test('throws if a difference between minHealthyPercentage and maxHealthyPercentage is greater than 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -2628,10 +2628,10 @@ describe('InstanceMaintenancePolicy', () => { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: ec2.MachineImage.latestAmazonLinux2(), - maxHealthPercentage: 200, - minHealthPercentage: 0, + maxHealthyPercentage: 200, + minHealthyPercentage: 0, }); - }).toThrow(/The difference between minHealthPercentage and maxHealthPercentage cannot be greater than 100, got 200/); + }).toThrow(/The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got 200/); }); }); From d3bf7916a7a2b50dc9b871e580c70a9ca69c8021 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Thu, 21 Dec 2023 14:52:46 +0900 Subject: [PATCH 18/18] refactor to order of min and max --- .../aws-autoscaling/lib/auto-scaling-group.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index bd69ef0eeceb0..90539d3738910 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -1473,8 +1473,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements defaultInstanceWarmup: props.defaultInstanceWarmup?.toSeconds(), capacityRebalance: props.capacityRebalance, instanceMaintenancePolicy: this.renderInstanceMaintenancePolicy( - props.maxHealthyPercentage, props.minHealthyPercentage, + props.maxHealthyPercentage, ), ...this.getLaunchSettings(launchConfig, props.launchTemplate ?? launchTemplateFromConfig, props.mixedInstancesPolicy), }; @@ -1891,28 +1891,28 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements } private renderInstanceMaintenancePolicy( - maxHealthyPercentage?: number, minHealthyPercentage?: number, + maxHealthyPercentage?: number, ): CfnAutoScalingGroup.InstanceMaintenancePolicyProperty | undefined { - if (maxHealthyPercentage === undefined && minHealthyPercentage === undefined) return; - if (maxHealthyPercentage === undefined || minHealthyPercentage === undefined) { + if (minHealthyPercentage === undefined && maxHealthyPercentage === undefined) return; + if (minHealthyPercentage === undefined || maxHealthyPercentage === undefined) { throw new Error(`Both or neither of minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: ${minHealthyPercentage} and maxHealthyPercentage: ${maxHealthyPercentage}`); } if ((minHealthyPercentage === -1 || maxHealthyPercentage === -1) && minHealthyPercentage !== maxHealthyPercentage) { throw new Error(`Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: ${minHealthyPercentage} and maxHealthyPercentage: ${maxHealthyPercentage}`); } - if (maxHealthyPercentage !== -1 && (maxHealthyPercentage < 100 || maxHealthyPercentage > 200)) { - throw new Error(`maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthyPercentage}`); - } if (minHealthyPercentage !== -1 && (minHealthyPercentage < 0 || minHealthyPercentage > 100)) { throw new Error(`minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthyPercentage}`); } + if (maxHealthyPercentage !== -1 && (maxHealthyPercentage < 100 || maxHealthyPercentage > 200)) { + throw new Error(`maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthyPercentage}`); + } if (maxHealthyPercentage - minHealthyPercentage > 100) { throw new Error(`The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got ${maxHealthyPercentage - minHealthyPercentage}`); } return { - maxHealthyPercentage, minHealthyPercentage, + maxHealthyPercentage, }; } }