Skip to content

Commit a4142aa

Browse files
authored
fix(autoscaling): AutoScalingGroup.requireImdsv2 throws error with LaunchTemplates (#27648)
This PR fixes the bug that AutoScalingGroup.requireImdsv2 throws error with LaunchTemplates. This handles `LaunchTemplate` in `AutoScalingGroupRequireImdsv2Aspect` when a feature flag `AUTOSCALING_GENERATE_LAUNCH_TEMPLATE` is true. Closes #27586. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a8f5326 commit a4142aa

File tree

8 files changed

+640
-12
lines changed

8 files changed

+640
-12
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/aws-cdk-asg-integ.assets.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/aws-cdk-asg-integ.template.json

+167
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,169 @@
888888
"IgnoreUnmodifiedGroupSizeProperties": true
889889
}
890890
}
891+
},
892+
"AsgWithIMDSv2InstanceSecurityGroupDE233317": {
893+
"Type": "AWS::EC2::SecurityGroup",
894+
"Properties": {
895+
"GroupDescription": "aws-cdk-asg-integ/AsgWithIMDSv2/InstanceSecurityGroup",
896+
"SecurityGroupEgress": [
897+
{
898+
"CidrIp": "0.0.0.0/0",
899+
"Description": "Allow all outbound traffic by default",
900+
"IpProtocol": "-1"
901+
}
902+
],
903+
"Tags": [
904+
{
905+
"Key": "Name",
906+
"Value": "aws-cdk-asg-integ/AsgWithIMDSv2"
907+
}
908+
],
909+
"VpcId": {
910+
"Ref": "VPCB9E5F0B4"
911+
}
912+
}
913+
},
914+
"AsgWithIMDSv2InstanceRole7C239C97": {
915+
"Type": "AWS::IAM::Role",
916+
"Properties": {
917+
"AssumeRolePolicyDocument": {
918+
"Statement": [
919+
{
920+
"Action": "sts:AssumeRole",
921+
"Effect": "Allow",
922+
"Principal": {
923+
"Service": "ec2.amazonaws.com"
924+
}
925+
}
926+
],
927+
"Version": "2012-10-17"
928+
},
929+
"Tags": [
930+
{
931+
"Key": "Name",
932+
"Value": "aws-cdk-asg-integ/AsgWithIMDSv2"
933+
}
934+
]
935+
}
936+
},
937+
"AsgWithIMDSv2InstanceProfile0D43F696": {
938+
"Type": "AWS::IAM::InstanceProfile",
939+
"Properties": {
940+
"Roles": [
941+
{
942+
"Ref": "AsgWithIMDSv2InstanceRole7C239C97"
943+
}
944+
]
945+
}
946+
},
947+
"AsgWithIMDSv2LaunchTemplateC4EE1BC2": {
948+
"Type": "AWS::EC2::LaunchTemplate",
949+
"Properties": {
950+
"LaunchTemplateData": {
951+
"IamInstanceProfile": {
952+
"Arn": {
953+
"Fn::GetAtt": [
954+
"AsgWithIMDSv2InstanceProfile0D43F696",
955+
"Arn"
956+
]
957+
}
958+
},
959+
"ImageId": {
960+
"Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amikernel510hvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter"
961+
},
962+
"InstanceType": "t2.micro",
963+
"MetadataOptions": {
964+
"HttpTokens": "required"
965+
},
966+
"Monitoring": {
967+
"Enabled": false
968+
},
969+
"SecurityGroupIds": [
970+
{
971+
"Fn::GetAtt": [
972+
"AsgWithIMDSv2InstanceSecurityGroupDE233317",
973+
"GroupId"
974+
]
975+
}
976+
],
977+
"TagSpecifications": [
978+
{
979+
"ResourceType": "instance",
980+
"Tags": [
981+
{
982+
"Key": "Name",
983+
"Value": "aws-cdk-asg-integ/AsgWithIMDSv2/LaunchTemplate"
984+
}
985+
]
986+
},
987+
{
988+
"ResourceType": "volume",
989+
"Tags": [
990+
{
991+
"Key": "Name",
992+
"Value": "aws-cdk-asg-integ/AsgWithIMDSv2/LaunchTemplate"
993+
}
994+
]
995+
}
996+
],
997+
"UserData": {
998+
"Fn::Base64": "#!/bin/bash"
999+
}
1000+
},
1001+
"TagSpecifications": [
1002+
{
1003+
"ResourceType": "launch-template",
1004+
"Tags": [
1005+
{
1006+
"Key": "Name",
1007+
"Value": "aws-cdk-asg-integ/AsgWithIMDSv2/LaunchTemplate"
1008+
}
1009+
]
1010+
}
1011+
]
1012+
},
1013+
"DependsOn": [
1014+
"AsgWithIMDSv2InstanceRole7C239C97"
1015+
]
1016+
},
1017+
"AsgWithIMDSv2ASGFD283CC8": {
1018+
"Type": "AWS::AutoScaling::AutoScalingGroup",
1019+
"Properties": {
1020+
"LaunchTemplate": {
1021+
"LaunchTemplateId": {
1022+
"Ref": "AsgWithIMDSv2LaunchTemplateC4EE1BC2"
1023+
},
1024+
"Version": {
1025+
"Fn::GetAtt": [
1026+
"AsgWithIMDSv2LaunchTemplateC4EE1BC2",
1027+
"LatestVersionNumber"
1028+
]
1029+
}
1030+
},
1031+
"MaxSize": "1",
1032+
"MinSize": "1",
1033+
"Tags": [
1034+
{
1035+
"Key": "Name",
1036+
"PropagateAtLaunch": true,
1037+
"Value": "aws-cdk-asg-integ/AsgWithIMDSv2"
1038+
}
1039+
],
1040+
"VPCZoneIdentifier": [
1041+
{
1042+
"Ref": "VPCPrivateSubnet1Subnet8BCA10E0"
1043+
},
1044+
{
1045+
"Ref": "VPCPrivateSubnet2SubnetCFCDAA7A"
1046+
}
1047+
]
1048+
},
1049+
"UpdatePolicy": {
1050+
"AutoScalingScheduledAction": {
1051+
"IgnoreUnmodifiedGroupSizeProperties": true
1052+
}
1053+
}
8911054
}
8921055
},
8931056
"Parameters": {
@@ -903,6 +1066,10 @@
9031066
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
9041067
"Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2"
9051068
},
1069+
"SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amikernel510hvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter": {
1070+
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
1071+
"Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-kernel-5.10-hvm-x86_64-gp2"
1072+
},
9061073
"BootstrapVersion": {
9071074
"Type": "AWS::SSM::Parameter::Value<String>",
9081075
"Default": "/cdk-bootstrap/hnb659fds/version",

packages/@aws-cdk-testing/framework-integ/test/aws-autoscaling/test/integ.asg-lt.js.snapshot/manifest.json

+37-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)