-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(asg): support keypair functionality for asg #29679
Changes from 1 commit
50c44d9
077cf5e
0f53e85
b08b7f0
24dc6e3
cb03ef3
e710a2f
14a6df4
7deb69e
4940cd1
73e2e99
b88ea01
f7a3896
51fda7f
7044409
355295f
78734fb
5b723f9
b0ebc8e
f13afe0
7b6bfb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,16 @@ export interface CommonAutoScalingGroupProps { | |
*/ | ||
readonly keyName?: string; | ||
|
||
/** | ||
* The SSH keypair to grant access to the instance. | ||
* | ||
* `keyName`, `launchTemplate` and `mixedInstancesPolicy` must not be specified | ||
* when this property is specified | ||
* | ||
* @default - No SSH access will be possible. | ||
*/ | ||
readonly keyPair?: ec2.IKeyPair; | ||
|
||
/** | ||
* Where to place instances within the VPC | ||
* | ||
|
@@ -1355,6 +1365,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,6 +1395,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements | |
|
||
launchTemplateFromConfig = new ec2.LaunchTemplate(this, 'LaunchTemplate', { | ||
machineImage: props.machineImage, | ||
keyPair: props.keyPair, | ||
keyName: props.keyName, | ||
instanceType: props.instanceType, | ||
detailedMonitoring: props.instanceMonitoring !== undefined && props.instanceMonitoring === Monitoring.DETAILED, | ||
|
@@ -1398,6 +1413,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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this validation because if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thanks for clarifying! Can you please add it to the documentation of the variable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! f7a3896 |
||
} | ||
|
||
// use delayed evaluation | ||
const imageConfig = props.machineImage.getImage(this); | ||
this._userData = props.userData ?? imageConfig.userData; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should mark the property as deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 4940cd1