Skip to content

Commit

Permalink
fix(autoscaling): AutoScalingGroup.requireImdsv2 throws error with La…
Browse files Browse the repository at this point in the history
…unchTemplates (#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*
  • Loading branch information
go-to-k authored Oct 26, 2023
1 parent a8f5326 commit a4142aa
Show file tree
Hide file tree
Showing 8 changed files with 640 additions and 12 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,169 @@
"IgnoreUnmodifiedGroupSizeProperties": true
}
}
},
"AsgWithIMDSv2InstanceSecurityGroupDE233317": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "aws-cdk-asg-integ/AsgWithIMDSv2/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/AsgWithIMDSv2"
}
],
"VpcId": {
"Ref": "VPCB9E5F0B4"
}
}
},
"AsgWithIMDSv2InstanceRole7C239C97": {
"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/AsgWithIMDSv2"
}
]
}
},
"AsgWithIMDSv2InstanceProfile0D43F696": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Roles": [
{
"Ref": "AsgWithIMDSv2InstanceRole7C239C97"
}
]
}
},
"AsgWithIMDSv2LaunchTemplateC4EE1BC2": {
"Type": "AWS::EC2::LaunchTemplate",
"Properties": {
"LaunchTemplateData": {
"IamInstanceProfile": {
"Arn": {
"Fn::GetAtt": [
"AsgWithIMDSv2InstanceProfile0D43F696",
"Arn"
]
}
},
"ImageId": {
"Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amikernel510hvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter"
},
"InstanceType": "t2.micro",
"MetadataOptions": {
"HttpTokens": "required"
},
"Monitoring": {
"Enabled": false
},
"SecurityGroupIds": [
{
"Fn::GetAtt": [
"AsgWithIMDSv2InstanceSecurityGroupDE233317",
"GroupId"
]
}
],
"TagSpecifications": [
{
"ResourceType": "instance",
"Tags": [
{
"Key": "Name",
"Value": "aws-cdk-asg-integ/AsgWithIMDSv2/LaunchTemplate"
}
]
},
{
"ResourceType": "volume",
"Tags": [
{
"Key": "Name",
"Value": "aws-cdk-asg-integ/AsgWithIMDSv2/LaunchTemplate"
}
]
}
],
"UserData": {
"Fn::Base64": "#!/bin/bash"
}
},
"TagSpecifications": [
{
"ResourceType": "launch-template",
"Tags": [
{
"Key": "Name",
"Value": "aws-cdk-asg-integ/AsgWithIMDSv2/LaunchTemplate"
}
]
}
]
},
"DependsOn": [
"AsgWithIMDSv2InstanceRole7C239C97"
]
},
"AsgWithIMDSv2ASGFD283CC8": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"LaunchTemplate": {
"LaunchTemplateId": {
"Ref": "AsgWithIMDSv2LaunchTemplateC4EE1BC2"
},
"Version": {
"Fn::GetAtt": [
"AsgWithIMDSv2LaunchTemplateC4EE1BC2",
"LatestVersionNumber"
]
}
},
"MaxSize": "1",
"MinSize": "1",
"Tags": [
{
"Key": "Name",
"PropagateAtLaunch": true,
"Value": "aws-cdk-asg-integ/AsgWithIMDSv2"
}
],
"VPCZoneIdentifier": [
{
"Ref": "VPCPrivateSubnet1Subnet8BCA10E0"
},
{
"Ref": "VPCPrivateSubnet2SubnetCFCDAA7A"
}
]
},
"UpdatePolicy": {
"AutoScalingScheduledAction": {
"IgnoreUnmodifiedGroupSizeProperties": true
}
}
}
},
"Parameters": {
Expand All @@ -903,6 +1066,10 @@
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
"Default": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2"
},
"SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amikernel510hvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
"Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-kernel-5.10-hvm-x86_64-gp2"
},
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a4142aa

Please sign in to comment.