Describe the bug
When using the new launchTemplate or mixedInstancesPolicy fields in an AutoScalingGroup with a Linux image the osType gets incorrectly set to ec2.OperatingSystemType.UNKNOWN.
This seems to be due to the fact that linux is the enum value "0" and logical OR is being used to coalesce the value (in case it is null).
This causes an error if used in combination with init (CloudFormationInit) since it uses the osType within the attach which throws 'Cannot attach CloudFormationInit to an unknown OS type' for unknown oses.
Expected Behavior
The AutoScalingGroup should correctly coalesce the 0/non-null (Linux) value for osType from the launchTemplate, and only coalesce for null values.
Current Behavior
The AutoScalingGroup incorrectly coalesces the 0/non-null (Linux) value for osType from the launchTemplate and assigns it to ec2.OperatingSystemType.UNKNOWN in the AutoScalingGroup.
Reproduction Steps
const launchTemplate = new LaunchTemplate(this, 'LaunchTemplate', {
instanceType: instanceType,
machineImage: new AmazonLinuxImage(),
role: role,
securityGroup: securityGroup,
});
const init = CloudFormationInit.fromElements(
InitCommand.shellCommand('/some/command/here')
);
new AutoScalingGroup(this, 'ASG', {
vpc: vpc,
launchTemplate: launchTemplate,
init: init
});
Possible Solution
switch the '||' on line 1209 of @aws-cdk/aws-autoscaling/lib/auto-scaling-groups.ts to '??'
Additional Information/Context
No response
CDK CLI Version
2.23.0
Framework Version
No response
Node.js Version
All
OS
All
Language
Typescript
Language Version
No response
Other information
No response
Describe the bug
When using the new launchTemplate or mixedInstancesPolicy fields in an AutoScalingGroup with a Linux image the osType gets incorrectly set to ec2.OperatingSystemType.UNKNOWN.
This seems to be due to the fact that linux is the enum value "0" and logical OR is being used to coalesce the value (in case it is null).
This causes an error if used in combination with init (CloudFormationInit) since it uses the osType within the attach which throws 'Cannot attach CloudFormationInit to an unknown OS type' for unknown oses.
Expected Behavior
The AutoScalingGroup should correctly coalesce the 0/non-null (Linux) value for osType from the launchTemplate, and only coalesce for null values.
Current Behavior
The AutoScalingGroup incorrectly coalesces the 0/non-null (Linux) value for osType from the launchTemplate and assigns it to ec2.OperatingSystemType.UNKNOWN in the AutoScalingGroup.
Reproduction Steps
Possible Solution
switch the '||' on line 1209 of @aws-cdk/aws-autoscaling/lib/auto-scaling-groups.ts to '??'
Additional Information/Context
No response
CDK CLI Version
2.23.0
Framework Version
No response
Node.js Version
All
OS
All
Language
Typescript
Language Version
No response
Other information
No response