diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.assets.json new file mode 100644 index 0000000000000..ac34ef81ba402 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.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-keypair.js.snapshot/AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.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-keypair.js.snapshot/aws-cdk-asg-integ.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/aws-cdk-asg-integ.assets.json new file mode 100644 index 0000000000000..908fdef0286cc --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/aws-cdk-asg-integ.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "e0a77dee93e8bb6342262073748a42af4ed8073f53646fd5b900a4d3baeb431d": { + "source": { + "path": "aws-cdk-asg-integ.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "e0a77dee93e8bb6342262073748a42af4ed8073f53646fd5b900a4d3baeb431d.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-keypair.js.snapshot/aws-cdk-asg-integ.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/aws-cdk-asg-integ.template.json new file mode 100644 index 0000000000000..ffa90d19af1d1 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/aws-cdk-asg-integ.template.json @@ -0,0 +1,604 @@ +{ + "Resources": { + "AsgKeyPairVPCAB15ADD7": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgKeyPairVPC" + } + ] + } + }, + "AsgKeyPairVPCPublicSubnet1SubnetEE75C076": { + "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-asg-integ/AsgKeyPairVPC/PublicSubnet1" + } + ], + "VpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "AsgKeyPairVPCPublicSubnet1RouteTableF3B77164": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1" + } + ], + "VpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "AsgKeyPairVPCPublicSubnet1RouteTableAssociation52D4312C": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "AsgKeyPairVPCPublicSubnet1RouteTableF3B77164" + }, + "SubnetId": { + "Ref": "AsgKeyPairVPCPublicSubnet1SubnetEE75C076" + } + } + }, + "AsgKeyPairVPCPublicSubnet1DefaultRouteE47759D2": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "AsgKeyPairVPCIGW20FC83AD" + }, + "RouteTableId": { + "Ref": "AsgKeyPairVPCPublicSubnet1RouteTableF3B77164" + } + }, + "DependsOn": [ + "AsgKeyPairVPCVPCGWC2DC249C" + ] + }, + "AsgKeyPairVPCPublicSubnet1EIPD55924EB": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1" + } + ] + } + }, + "AsgKeyPairVPCPublicSubnet1NATGateway53893214": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "AsgKeyPairVPCPublicSubnet1EIPD55924EB", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "AsgKeyPairVPCPublicSubnet1SubnetEE75C076" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1" + } + ] + }, + "DependsOn": [ + "AsgKeyPairVPCPublicSubnet1DefaultRouteE47759D2", + "AsgKeyPairVPCPublicSubnet1RouteTableAssociation52D4312C" + ] + }, + "AsgKeyPairVPCPublicSubnet2Subnet5FEA12AF": { + "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-asg-integ/AsgKeyPairVPC/PublicSubnet2" + } + ], + "VpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "AsgKeyPairVPCPublicSubnet2RouteTableA5C10D51": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2" + } + ], + "VpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "AsgKeyPairVPCPublicSubnet2RouteTableAssociation679CE895": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "AsgKeyPairVPCPublicSubnet2RouteTableA5C10D51" + }, + "SubnetId": { + "Ref": "AsgKeyPairVPCPublicSubnet2Subnet5FEA12AF" + } + } + }, + "AsgKeyPairVPCPublicSubnet2DefaultRoute8CFFDC30": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "AsgKeyPairVPCIGW20FC83AD" + }, + "RouteTableId": { + "Ref": "AsgKeyPairVPCPublicSubnet2RouteTableA5C10D51" + } + }, + "DependsOn": [ + "AsgKeyPairVPCVPCGWC2DC249C" + ] + }, + "AsgKeyPairVPCPublicSubnet2EIP4A16F5E3": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2" + } + ] + } + }, + "AsgKeyPairVPCPublicSubnet2NATGateway154AF535": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "AsgKeyPairVPCPublicSubnet2EIP4A16F5E3", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "AsgKeyPairVPCPublicSubnet2Subnet5FEA12AF" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2" + } + ] + }, + "DependsOn": [ + "AsgKeyPairVPCPublicSubnet2DefaultRoute8CFFDC30", + "AsgKeyPairVPCPublicSubnet2RouteTableAssociation679CE895" + ] + }, + "AsgKeyPairVPCPrivateSubnet1SubnetE682643B": { + "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-asg-integ/AsgKeyPairVPC/PrivateSubnet1" + } + ], + "VpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "AsgKeyPairVPCPrivateSubnet1RouteTable0CE94099": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet1" + } + ], + "VpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "AsgKeyPairVPCPrivateSubnet1RouteTableAssociation936C35B8": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "AsgKeyPairVPCPrivateSubnet1RouteTable0CE94099" + }, + "SubnetId": { + "Ref": "AsgKeyPairVPCPrivateSubnet1SubnetE682643B" + } + } + }, + "AsgKeyPairVPCPrivateSubnet1DefaultRoute1E35D270": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "AsgKeyPairVPCPublicSubnet1NATGateway53893214" + }, + "RouteTableId": { + "Ref": "AsgKeyPairVPCPrivateSubnet1RouteTable0CE94099" + } + } + }, + "AsgKeyPairVPCPrivateSubnet2Subnet0149E1CD": { + "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-asg-integ/AsgKeyPairVPC/PrivateSubnet2" + } + ], + "VpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "AsgKeyPairVPCPrivateSubnet2RouteTable718F0158": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet2" + } + ], + "VpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "AsgKeyPairVPCPrivateSubnet2RouteTableAssociation807E4E20": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "AsgKeyPairVPCPrivateSubnet2RouteTable718F0158" + }, + "SubnetId": { + "Ref": "AsgKeyPairVPCPrivateSubnet2Subnet0149E1CD" + } + } + }, + "AsgKeyPairVPCPrivateSubnet2DefaultRouteE2EE5F73": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "AsgKeyPairVPCPublicSubnet2NATGateway154AF535" + }, + "RouteTableId": { + "Ref": "AsgKeyPairVPCPrivateSubnet2RouteTable718F0158" + } + } + }, + "AsgKeyPairVPCIGW20FC83AD": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgKeyPairVPC" + } + ] + } + }, + "AsgKeyPairVPCVPCGWC2DC249C": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "InternetGatewayId": { + "Ref": "AsgKeyPairVPCIGW20FC83AD" + }, + "VpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "MyKeyPair659209CA": { + "Type": "AWS::EC2::KeyPair", + "Properties": { + "KeyFormat": "pem", + "KeyName": "awscdkasgintegMyKeyPair1AD26B9D", + "KeyType": "rsa" + } + }, + "AsgWithKeyPairInstanceSecurityGroup31DE792D": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "aws-cdk-asg-integ/AsgWithKeyPair/InstanceSecurityGroup", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgWithKeyPair" + } + ], + "VpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "AsgWithKeyPairInstanceRoleFFF6636B": { + "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-asg-integ/AsgWithKeyPair" + } + ] + } + }, + "AsgWithKeyPairInstanceProfileBF737BEF": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "AsgWithKeyPairInstanceRoleFFF6636B" + } + ] + } + }, + "AsgWithKeyPairLaunchTemplate4333E477": { + "Type": "AWS::EC2::LaunchTemplate", + "Properties": { + "LaunchTemplateData": { + "IamInstanceProfile": { + "Arn": { + "Fn::GetAtt": [ + "AsgWithKeyPairInstanceProfileBF737BEF", + "Arn" + ] + } + }, + "ImageId": { + "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amikernel510hvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + }, + "InstanceType": "t2.micro", + "KeyName": { + "Ref": "MyKeyPair659209CA" + }, + "Monitoring": { + "Enabled": false + }, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "AsgWithKeyPairInstanceSecurityGroup31DE792D", + "GroupId" + ] + } + ], + "TagSpecifications": [ + { + "ResourceType": "instance", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgWithKeyPair/LaunchTemplate" + } + ] + }, + { + "ResourceType": "volume", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgWithKeyPair/LaunchTemplate" + } + ] + } + ], + "UserData": { + "Fn::Base64": "#!/bin/bash" + } + }, + "TagSpecifications": [ + { + "ResourceType": "launch-template", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-asg-integ/AsgWithKeyPair/LaunchTemplate" + } + ] + } + ] + }, + "DependsOn": [ + "AsgWithKeyPairInstanceRoleFFF6636B" + ] + }, + "AsgWithKeyPairASG41E76E3F": { + "Type": "AWS::AutoScaling::AutoScalingGroup", + "Properties": { + "LaunchTemplate": { + "LaunchTemplateId": { + "Ref": "AsgWithKeyPairLaunchTemplate4333E477" + }, + "Version": { + "Fn::GetAtt": [ + "AsgWithKeyPairLaunchTemplate4333E477", + "LatestVersionNumber" + ] + } + }, + "MaxSize": "1", + "MinSize": "1", + "Tags": [ + { + "Key": "Name", + "PropagateAtLaunch": true, + "Value": "aws-cdk-asg-integ/AsgWithKeyPair" + } + ], + "VPCZoneIdentifier": [ + { + "Ref": "AsgKeyPairVPCPrivateSubnet1SubnetE682643B" + }, + { + "Ref": "AsgKeyPairVPCPrivateSubnet2Subnet0149E1CD" + } + ] + }, + "UpdatePolicy": { + "AutoScalingScheduledAction": { + "IgnoreUnmodifiedGroupSizeProperties": true + } + } + } + }, + "Parameters": { + "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amikernel510hvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-kernel-5.10-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-keypair.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/integ.json new file mode 100644 index 0000000000000..089f09dc389ac --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.0", + "testCases": { + "AsgIntegKeyPair/DefaultTest": { + "stacks": [ + "aws-cdk-asg-integ" + ], + "assertionStack": "AsgIntegKeyPair/DefaultTest/DeployAssert", + "assertionStackName": "AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/manifest.json new file mode 100644 index 0000000000000..22d3c1a3dd68a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/manifest.json @@ -0,0 +1,287 @@ +{ + "version": "36.0.0", + "artifacts": { + "aws-cdk-asg-integ.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "aws-cdk-asg-integ.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "aws-cdk-asg-integ": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "aws-cdk-asg-integ.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}/e0a77dee93e8bb6342262073748a42af4ed8073f53646fd5b900a4d3baeb431d.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "aws-cdk-asg-integ.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-asg-integ.assets" + ], + "metadata": { + "/aws-cdk-asg-integ/AsgKeyPairVPC/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCAB15ADD7" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet1SubnetEE75C076" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet1RouteTableF3B77164" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet1RouteTableAssociation52D4312C" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet1DefaultRouteE47759D2" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet1EIPD55924EB" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet1NATGateway53893214" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet2Subnet5FEA12AF" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet2RouteTableA5C10D51" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet2RouteTableAssociation679CE895" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet2DefaultRoute8CFFDC30" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet2EIP4A16F5E3" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPublicSubnet2NATGateway154AF535" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPrivateSubnet1SubnetE682643B" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPrivateSubnet1RouteTable0CE94099" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPrivateSubnet1RouteTableAssociation936C35B8" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPrivateSubnet1DefaultRoute1E35D270" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPrivateSubnet2Subnet0149E1CD" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPrivateSubnet2RouteTable718F0158" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPrivateSubnet2RouteTableAssociation807E4E20" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCPrivateSubnet2DefaultRouteE2EE5F73" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/IGW": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCIGW20FC83AD" + } + ], + "/aws-cdk-asg-integ/AsgKeyPairVPC/VPCGW": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgKeyPairVPCVPCGWC2DC249C" + } + ], + "/aws-cdk-asg-integ/MyKeyPair/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyKeyPair659209CA" + } + ], + "/aws-cdk-asg-integ/AsgWithKeyPair/InstanceSecurityGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgWithKeyPairInstanceSecurityGroup31DE792D" + } + ], + "/aws-cdk-asg-integ/AsgWithKeyPair/InstanceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgWithKeyPairInstanceRoleFFF6636B" + } + ], + "/aws-cdk-asg-integ/AsgWithKeyPair/InstanceProfile": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgWithKeyPairInstanceProfileBF737BEF" + } + ], + "/aws-cdk-asg-integ/AsgWithKeyPair/LaunchTemplate/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgWithKeyPairLaunchTemplate4333E477" + } + ], + "/aws-cdk-asg-integ/AsgWithKeyPair/ASG": [ + { + "type": "aws:cdk:logicalId", + "data": "AsgWithKeyPairASG41E76E3F" + } + ], + "/aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [ + { + "type": "aws:cdk:logicalId", + "data": "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amikernel510hvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + } + ], + "/aws-cdk-asg-integ/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/aws-cdk-asg-integ/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "aws-cdk-asg-integ" + }, + "AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.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": [ + "AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.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": [ + "AsgIntegKeyPairDefaultTestDeployAssert4EC47FB2.assets" + ], + "metadata": { + "/AsgIntegKeyPair/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/AsgIntegKeyPair/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "AsgIntegKeyPair/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-keypair.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/tree.json new file mode 100644 index 0000000000000..993ad0c3ac787 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.js.snapshot/tree.json @@ -0,0 +1,1037 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "aws-cdk-asg-integ": { + "id": "aws-cdk-asg-integ", + "path": "aws-cdk-asg-integ", + "children": { + "AsgKeyPairVPC": { + "id": "AsgKeyPairVPC", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/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-asg-integ/AsgKeyPairVPC" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnVPC", + "version": "0.0.0" + } + }, + "PublicSubnet1": { + "id": "PublicSubnet1", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/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-asg-integ/AsgKeyPairVPC/PublicSubnet1" + } + ], + "vpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1" + } + ], + "vpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "AsgKeyPairVPCPublicSubnet1RouteTableF3B77164" + }, + "subnetId": { + "Ref": "AsgKeyPairVPCPublicSubnet1SubnetEE75C076" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "AsgKeyPairVPCIGW20FC83AD" + }, + "routeTableId": { + "Ref": "AsgKeyPairVPCPublicSubnet1RouteTableF3B77164" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet1/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "AsgKeyPairVPCPublicSubnet1EIPD55924EB", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "AsgKeyPairVPCPublicSubnet1SubnetEE75C076" + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgKeyPairVPC/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-asg-integ/AsgKeyPairVPC/PublicSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/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-asg-integ/AsgKeyPairVPC/PublicSubnet2" + } + ], + "vpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2" + } + ], + "vpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "AsgKeyPairVPCPublicSubnet2RouteTableA5C10D51" + }, + "subnetId": { + "Ref": "AsgKeyPairVPCPublicSubnet2Subnet5FEA12AF" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "AsgKeyPairVPCIGW20FC83AD" + }, + "routeTableId": { + "Ref": "AsgKeyPairVPCPublicSubnet2RouteTableA5C10D51" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PublicSubnet2/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "AsgKeyPairVPCPublicSubnet2EIP4A16F5E3", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "AsgKeyPairVPCPublicSubnet2Subnet5FEA12AF" + }, + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgKeyPairVPC/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-asg-integ/AsgKeyPairVPC/PrivateSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/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-asg-integ/AsgKeyPairVPC/PrivateSubnet1" + } + ], + "vpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet1/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet1" + } + ], + "vpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "AsgKeyPairVPCPrivateSubnet1RouteTable0CE94099" + }, + "subnetId": { + "Ref": "AsgKeyPairVPCPrivateSubnet1SubnetE682643B" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "AsgKeyPairVPCPublicSubnet1NATGateway53893214" + }, + "routeTableId": { + "Ref": "AsgKeyPairVPCPrivateSubnet1RouteTable0CE94099" + } + } + }, + "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-asg-integ/AsgKeyPairVPC/PrivateSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/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-asg-integ/AsgKeyPairVPC/PrivateSubnet2" + } + ], + "vpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet2/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet2" + } + ], + "vpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "AsgKeyPairVPCPrivateSubnet2RouteTable718F0158" + }, + "subnetId": { + "Ref": "AsgKeyPairVPCPrivateSubnet2Subnet0149E1CD" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/PrivateSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "AsgKeyPairVPCPublicSubnet2NATGateway154AF535" + }, + "routeTableId": { + "Ref": "AsgKeyPairVPCPrivateSubnet2RouteTable718F0158" + } + } + }, + "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-asg-integ/AsgKeyPairVPC/IGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::InternetGateway", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgKeyPairVPC" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnInternetGateway", + "version": "0.0.0" + } + }, + "VPCGW": { + "id": "VPCGW", + "path": "aws-cdk-asg-integ/AsgKeyPairVPC/VPCGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPCGatewayAttachment", + "aws:cdk:cloudformation:props": { + "internetGatewayId": { + "Ref": "AsgKeyPairVPCIGW20FC83AD" + }, + "vpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnVPCGatewayAttachment", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.Vpc", + "version": "0.0.0" + } + }, + "MyKeyPair": { + "id": "MyKeyPair", + "path": "aws-cdk-asg-integ/MyKeyPair", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-asg-integ/MyKeyPair/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::KeyPair", + "aws:cdk:cloudformation:props": { + "keyFormat": "pem", + "keyName": "awscdkasgintegMyKeyPair1AD26B9D", + "keyType": "rsa" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnKeyPair", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.KeyPair", + "version": "0.0.0" + } + }, + "AsgWithKeyPair": { + "id": "AsgWithKeyPair", + "path": "aws-cdk-asg-integ/AsgWithKeyPair", + "children": { + "InstanceSecurityGroup": { + "id": "InstanceSecurityGroup", + "path": "aws-cdk-asg-integ/AsgWithKeyPair/InstanceSecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-asg-integ/AsgWithKeyPair/InstanceSecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "aws-cdk-asg-integ/AsgWithKeyPair/InstanceSecurityGroup", + "securityGroupEgress": [ + { + "cidrIp": "0.0.0.0/0", + "description": "Allow all outbound traffic by default", + "ipProtocol": "-1" + } + ], + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgWithKeyPair" + } + ], + "vpcId": { + "Ref": "AsgKeyPairVPCAB15ADD7" + } + } + }, + "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-asg-integ/AsgWithKeyPair/InstanceRole", + "children": { + "ImportInstanceRole": { + "id": "ImportInstanceRole", + "path": "aws-cdk-asg-integ/AsgWithKeyPair/InstanceRole/ImportInstanceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-cdk-asg-integ/AsgWithKeyPair/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-asg-integ/AsgWithKeyPair" + } + ] + } + }, + "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-asg-integ/AsgWithKeyPair/InstanceProfile", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::InstanceProfile", + "aws:cdk:cloudformation:props": { + "roles": [ + { + "Ref": "AsgWithKeyPairInstanceRoleFFF6636B" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnInstanceProfile", + "version": "0.0.0" + } + }, + "ImportedInstanceProfile": { + "id": "ImportedInstanceProfile", + "path": "aws-cdk-asg-integ/AsgWithKeyPair/ImportedInstanceProfile", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "LaunchTemplate": { + "id": "LaunchTemplate", + "path": "aws-cdk-asg-integ/AsgWithKeyPair/LaunchTemplate", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-asg-integ/AsgWithKeyPair/LaunchTemplate/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::LaunchTemplate", + "aws:cdk:cloudformation:props": { + "launchTemplateData": { + "iamInstanceProfile": { + "arn": { + "Fn::GetAtt": [ + "AsgWithKeyPairInstanceProfileBF737BEF", + "Arn" + ] + } + }, + "imageId": { + "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amikernel510hvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + }, + "instanceType": "t2.micro", + "keyName": { + "Ref": "MyKeyPair659209CA" + }, + "monitoring": { + "enabled": false + }, + "securityGroupIds": [ + { + "Fn::GetAtt": [ + "AsgWithKeyPairInstanceSecurityGroup31DE792D", + "GroupId" + ] + } + ], + "tagSpecifications": [ + { + "resourceType": "instance", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgWithKeyPair/LaunchTemplate" + } + ] + }, + { + "resourceType": "volume", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgWithKeyPair/LaunchTemplate" + } + ] + } + ], + "userData": { + "Fn::Base64": "#!/bin/bash" + } + }, + "tagSpecifications": [ + { + "resourceType": "launch-template", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgWithKeyPair/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-asg-integ/AsgWithKeyPair/ASG", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::AutoScaling::AutoScalingGroup", + "aws:cdk:cloudformation:props": { + "launchTemplate": { + "launchTemplateId": { + "Ref": "AsgWithKeyPairLaunchTemplate4333E477" + }, + "version": { + "Fn::GetAtt": [ + "AsgWithKeyPairLaunchTemplate4333E477", + "LatestVersionNumber" + ] + } + }, + "maxSize": "1", + "minSize": "1", + "tags": [ + { + "key": "Name", + "value": "aws-cdk-asg-integ/AsgWithKeyPair", + "propagateAtLaunch": true + } + ], + "vpcZoneIdentifier": [ + { + "Ref": "AsgKeyPairVPCPrivateSubnet1SubnetE682643B" + }, + { + "Ref": "AsgKeyPairVPCPrivateSubnet2Subnet0149E1CD" + } + ] + } + }, + "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-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": { + "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter", + "path": "aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-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-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118": { + "id": "SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-hvm-x86_64-gp2:C96584B6-F00A-464E-AD19-53AFF4B05118", + "path": "aws-cdk-asg-integ/SsmParameterValue:--aws--service--ami-amazon-linux-latest--amzn2-ami-kernel-5.10-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-asg-integ/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "aws-cdk-asg-integ/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "AsgIntegKeyPair": { + "id": "AsgIntegKeyPair", + "path": "AsgIntegKeyPair", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "AsgIntegKeyPair/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "AsgIntegKeyPair/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "AsgIntegKeyPair/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "AsgIntegKeyPair/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "AsgIntegKeyPair/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-keypair.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.ts new file mode 100644 index 0000000000000..db29a7fbf9446 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-keypair.ts @@ -0,0 +1,28 @@ +#!/usr/bin/env node +import * as ec2 from 'aws-cdk-lib/aws-ec2'; +import * as cdk from 'aws-cdk-lib'; +import * as autoscaling from 'aws-cdk-lib/aws-autoscaling'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import { AUTOSCALING_GENERATE_LAUNCH_TEMPLATE } from 'aws-cdk-lib/cx-api'; + +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'aws-cdk-asg-integ'); +stack.node.setContext(AUTOSCALING_GENERATE_LAUNCH_TEMPLATE, true); + +const vpc = new ec2.Vpc(stack, 'AsgKeyPairVPC', { + restrictDefaultSecurityGroup: false, + maxAzs: 2, +}); + +new autoscaling.AutoScalingGroup(stack, 'AsgWithKeyPair', { + instanceType: new ec2.InstanceType('t2.micro'), + machineImage: ec2.MachineImage.latestAmazonLinux2(), + keyPair: new ec2.KeyPair(stack, 'MyKeyPair'), + vpc, +}); + +new IntegTest(app, 'AsgIntegKeyPair', { + testCases: [stack], +}); + +app.synth(); diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index ff03c316549ed..b8745f86ff860 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -23,7 +23,8 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { Creating an `AutoScalingGroup` from a Launch Configuration has been deprecated. All new accounts created after December 31, 2023 will no longer be able to create Launch Configurations. With the `@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig` feature flag set to true, `AutoScalingGroup` properties used to create a Launch Configuration will now be used to create a `LaunchTemplate` using a [Launch Configuration to `LaunchTemplate` mapping](https://docs.aws.amazon.com/autoscaling/ec2/userguide/migrate-launch-configurations-with-cloudformation.html#launch-configuration-mapping-reference). Specifically, the following `AutoScalingGroup` properties will be used to generate a `LaunchTemplate`: * machineImage -* keyName +* keyName (deprecated, prefer keyPair) +* keyPair * instanceType * instanceMonitoring * securityGroup @@ -738,6 +739,30 @@ new autoscaling.AutoScalingGroup(this, 'ASG', { }); ``` +## Configuring KeyPair for instances + +You can use a keyPair to build your asg when you decide not to use a ready-made LanchTemplate. + +To configure KeyPair for an autoscaling group, pass the `keyPair` as a prop: + +```ts +declare const vpc: ec2.Vpc; +declare const instanceType: ec2.InstanceType; +declare const machineImage: ec2.IMachineImage; + +const myKeyPair = new ec2.KeyPair(this, 'MyKeyPair'); + +new autoscaling.AutoScalingGroup(this, 'ASG', { + vpc, + instanceType, + machineImage, + + // ... + + keyPair: myKeyPair, +}); +``` + ## Future work * [ ] CloudWatch Events (impossible to add currently as the AutoScalingGroup ARN is 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 eab143ef5d80c..05ea9b3a4c148 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 @@ -83,10 +83,26 @@ export interface CommonAutoScalingGroupProps { * * `launchTemplate` and `mixedInstancesPolicy` must not be specified when this property is specified * + * You can either specify `keyPair` or `keyName`, not both. + * * @default - No SSH access will be possible. + * @deprecated - Use `keyPair` instead - https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2-readme.html#using-an-existing-ec2-key-pair */ readonly keyName?: string; + /** + * The SSH keypair to grant access to the instance. + * + * Feature flag `AUTOSCALING_GENERATE_LAUNCH_TEMPLATE` must be enabled to use this property. + * + * `launchTemplate` and `mixedInstancesPolicy` must not be specified when this property is specified. + * + * You can either specify `keyPair` or `keyName`, not both. + * + * @default - No SSH access will be possible. + */ + readonly keyPair?: ec2.IKeyPair; + /** * Where to place instances within the VPC * @@ -1355,6 +1371,10 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements throw new Error('Setting \'instanceType\' is required when \'launchTemplate\' and \'mixedInstancesPolicy\' is not set'); } + if (props.keyName && props.keyPair) { + throw new Error('Cannot specify both of \'keyName\' and \'keyPair\'; prefer \'keyPair\''); + } + Tags.of(this).add(NAME_TAG, this.node.path); this.securityGroup = props.securityGroup || new ec2.SecurityGroup(this, 'InstanceSecurityGroup', { @@ -1381,7 +1401,6 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements launchTemplateFromConfig = new ec2.LaunchTemplate(this, 'LaunchTemplate', { machineImage: props.machineImage, - keyName: props.keyName, instanceType: props.instanceType, detailedMonitoring: props.instanceMonitoring !== undefined && props.instanceMonitoring === Monitoring.DETAILED, securityGroup: this.securityGroup, @@ -1390,6 +1409,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements spotOptions: props.spotPrice !== undefined ? { maxPrice: parseFloat(props.spotPrice) } : undefined, blockDevices: props.blockDevices, instanceProfile, + keyPair: props.keyPair, + ...(props.keyName ? { keyName: props.keyName } : {}), }); this.osType = launchTemplateFromConfig.osType!; @@ -1398,6 +1419,10 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements this._connections = new ec2.Connections({ securityGroups: [this.securityGroup] }); this.securityGroups = [this.securityGroup]; + if (props.keyPair) { + throw new Error('Can only use \'keyPair\' when feature flag \'AUTOSCALING_GENERATE_LAUNCH_TEMPLATE\' is set'); + } + // use delayed evaluation const imageConfig = props.machineImage.getImage(this); this._userData = props.userData ?? imageConfig.userData; @@ -1718,6 +1743,9 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements if (props.keyName) { throw new Error('Setting \'keyName\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set'); } + if (props.keyPair) { + throw new Error('Setting \'keyPair\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set'); + } if (props.instanceMonitoring) { throw new Error('Setting \'instanceMonitoring\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set'); } 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 5096a78132ce3..1ccbdd5f423ba 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 @@ -2360,6 +2360,127 @@ describe('auto scaling group', () => { }); }); + test('can configure keyPair', () => { + // GIVE + const stack = new cdk.Stack(); + stack.node.setContext(AUTOSCALING_GENERATE_LAUNCH_TEMPLATE, true); + const vpc = mockVpc(stack); + const keyPair = new ec2.KeyPair(stack, 'MyKeyPair', { keyPairName: 'MyKeyPair' }); + + // WHEN + new autoscaling.AutoScalingGroup(stack, 'MyAutoScalingGroup', { + vpc, + instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO), + machineImage: new ec2.AmazonLinuxImage(), + keyPair: keyPair, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::EC2::LaunchTemplate', { + LaunchTemplateData: { + KeyName: { + Ref: 'MyKeyPair659209CA', + }, + }, + }); + }); + + test('keyPair should throw if @aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig is false', () => { + // WHEN + const stack = new cdk.Stack(); + stack.node.setContext(AUTOSCALING_GENERATE_LAUNCH_TEMPLATE, false); + const vpc = mockVpc(stack); + const keyPair = new ec2.KeyPair(stack, 'MyKeyPair', { keyPairName: 'MyKeyPair' }); + + // THEN + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'MyASG', { + vpc, + instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO), + machineImage: new ec2.AmazonLinuxImage(), + keyPair: keyPair, + }); + }).toThrow("Can only use \'keyPair\' when feature flag \'AUTOSCALING_GENERATE_LAUNCH_TEMPLATE\' is set"); + }); + + test('keyPair and keyName cannot be defined together', () => { + // WHEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + const keyPair = new ec2.KeyPair(stack, 'MyKeyPair', { keyPairName: 'MyKeyPair' }); + + // THEN + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'MyASG', { + vpc, + instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO), + machineImage: new ec2.AmazonLinuxImage(), + keyName: 'MyKeyPair', + keyPair: keyPair, + }); + }).toThrow("Cannot specify both of \'keyName\' and \'keyPair\'; prefer \'keyPair\'"); + }); + + test('keyPair and launchTemplate cannot be defined together', () => { + // WHEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + const keyPair = new ec2.KeyPair(stack, 'MyKeyPair', { keyPairName: 'MyKeyPair' }); + + // THEN + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'MyASG', { + vpc, + launchTemplate: new LaunchTemplate(stack, 'in-stack-lt', { + instanceType: new ec2.InstanceType('t3.micro'), + machineImage: new ec2.AmazonLinuxImage({ + generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2, + cpuType: ec2.AmazonLinuxCpuType.X86_64, + }), + }), + keyPair: keyPair, + }); + }).toThrow("Setting \'keyPair\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set"); + }); + + test('keyName and mixedInstancesPolicy cannot be defined together', () => { + // WHEN + const stack = new cdk.Stack(); + const vpc = mockVpc(stack); + const keyPair = new ec2.KeyPair(stack, 'MyKeyPair', { keyPairName: 'MyKeyPair' }); + const lt = new LaunchTemplate(stack, 'in-stack-lt', { + instanceType: new ec2.InstanceType('t3.micro'), + machineImage: new ec2.AmazonLinuxImage({ + generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2, + cpuType: ec2.AmazonLinuxCpuType.X86_64, + }), + }); + + // THEN + expect(() => { + new autoscaling.AutoScalingGroup(stack, 'mip-asg', { + mixedInstancesPolicy: { + launchTemplate: lt, + launchTemplateOverrides: [{ + instanceType: new InstanceType('t4g.micro'), + launchTemplate: lt, + weightedCapacity: 9, + }], + instancesDistribution: { + onDemandAllocationStrategy: OnDemandAllocationStrategy.PRIORITIZED, + onDemandBaseCapacity: 1, + onDemandPercentageAboveBaseCapacity: 2, + spotAllocationStrategy: SpotAllocationStrategy.CAPACITY_OPTIMIZED_PRIORITIZED, + spotInstancePools: 3, + spotMaxPrice: '4', + }, + }, + keyPair: keyPair, + vpc, + }); + }).toThrow("Setting \'keyPair\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set"); + }); + }); function mockVpc(stack: cdk.Stack) {