-
Notifications
You must be signed in to change notification settings - Fork 0
Fix launch template optional API params #3
Changes from all commits
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 |
---|---|---|
|
@@ -55169,17 +55169,35 @@ async function startEc2Instance(label, githubRegistrationToken) { | |
const userData = buildUserDataScript(githubRegistrationToken, label); | ||
|
||
const params = { | ||
ImageId: config.input.ec2ImageId, | ||
InstanceType: config.input.ec2InstanceType, | ||
MinCount: config.input.runnerCount, | ||
MaxCount: config.input.runnerCount, | ||
UserData: Buffer.from(userData.join('\n')).toString('base64'), | ||
SubnetId: config.input.subnetId, | ||
SecurityGroupIds: [config.input.securityGroupId], | ||
IamInstanceProfile: { Name: config.input.iamRoleName }, | ||
TagSpecifications: config.tagSpecifications, | ||
}; | ||
|
||
if (config.input.ec2LaunchTemplate) { | ||
params.LaunchTemplate = { | ||
LaunchTemplateName: config.input.ec2LaunchTemplate | ||
}; | ||
} | ||
|
||
// when using a launch template any or all of these are optional | ||
if (config.input.ec2ImageId) { | ||
params.ImageId = config.input.ec2ImageId; | ||
} | ||
if (config.input.ec2InstanceType) { | ||
params.InstanceType = config.input.ec2InstanceType; | ||
} | ||
if (config.input.subnetId) { | ||
params.SubnetId = config.input.subnetId; | ||
} | ||
if (config.input.securityGroupId) { | ||
params.SecurityGroupIds = [config.input.securityGroupId]; | ||
} | ||
if (config.input.iamRoleName) { | ||
params.IamInstanceProfile = { Name: config.input.iamRoleName }; | ||
} | ||
|
||
try { | ||
const result = await ec2.runInstances(params).promise(); | ||
const ec2InstanceIds = result.Instances.map(x => x.InstanceId).join(); | ||
|
@@ -55254,6 +55272,7 @@ class Config { | |
iamRoleName: core.getInput('iam-role-name'), | ||
runnerHomeDir: core.getInput('runner-home-dir'), | ||
runnerCount: core.getInput('runner-count'), | ||
ec2LaunchTemplate: core.getInput('ec2-launch-template'), | ||
}; | ||
|
||
const tags = JSON.parse(core.getInput('aws-resource-tags')); | ||
|
@@ -55283,7 +55302,9 @@ class Config { | |
} | ||
|
||
if (this.input.mode === 'start') { | ||
if (!this.input.ec2ImageId || !this.input.ec2InstanceType || !this.input.subnetId || !this.input.securityGroupId) { | ||
const isSet = param => param; | ||
const params = [this.input.ec2ImageId, this.input.ec2InstanceType, this.input.subnetId, this.input.securityGroupId]; | ||
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 was a bit confused about where this line came from: it's from #2, and appears here because the dist got rebuilt. |
||
if (!(this.input.ec2LaunchTemplate || params.every(isSet))) { | ||
throw new Error(`Not all the required inputs are provided for the 'start' mode`); | ||
} | ||
} else if (this.input.mode === 'stop') { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,14 +38,9 @@ async function startEc2Instance(label, githubRegistrationToken) { | |
const userData = buildUserDataScript(githubRegistrationToken, label); | ||
|
||
const params = { | ||
ImageId: config.input.ec2ImageId, | ||
InstanceType: config.input.ec2InstanceType, | ||
MinCount: config.input.runnerCount, | ||
MaxCount: config.input.runnerCount, | ||
UserData: Buffer.from(userData.join('\n')).toString('base64'), | ||
SubnetId: config.input.subnetId, | ||
SecurityGroupIds: [config.input.securityGroupId], | ||
IamInstanceProfile: { Name: config.input.iamRoleName }, | ||
TagSpecifications: config.tagSpecifications, | ||
}; | ||
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 might be being dumb, but where do you pass in a 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. It came from the upstream PR we merged, so not in this diff, but just below here on line 52. Click the little expandy button. 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. This PR is just a fix for the upstream one, which didn't quite work. machulav#70 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. Ah! 💡 Thanks for the context 👌 |
||
|
||
|
@@ -55,6 +50,23 @@ async function startEc2Instance(label, githubRegistrationToken) { | |
}; | ||
} | ||
|
||
// when using a launch template any or all of these are optional | ||
if (config.input.ec2ImageId) { | ||
params.ImageId = config.input.ec2ImageId; | ||
} | ||
if (config.input.ec2InstanceType) { | ||
params.InstanceType = config.input.ec2InstanceType; | ||
} | ||
if (config.input.subnetId) { | ||
params.SubnetId = config.input.subnetId; | ||
} | ||
if (config.input.securityGroupId) { | ||
params.SecurityGroupIds = [config.input.securityGroupId]; | ||
} | ||
if (config.input.iamRoleName) { | ||
params.IamInstanceProfile = { Name: config.input.iamRoleName }; | ||
} | ||
|
||
try { | ||
const result = await ec2.runInstances(params).promise(); | ||
const ec2InstanceIds = result.Instances.map(x => x.InstanceId).join(); | ||
|
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.
this could probably be done with an array of property names and dynamically checking
config.input
for them & adding them toparams
. But it would look like:which is a bit dense