Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ inputs:
required: false
subnet-id:
description: >-
VPC Subnet Id. The subnet should belong to the same VPC as the specified security group.
VPC Subnet Id. You may provide a comma-separated list of subnet ids to try multiple subnets.
The subnet should belong to the same VPC as the specified security group.
This input is required if you use the 'start' mode.
required: false
security-group-id:
Expand Down
45 changes: 25 additions & 20 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55575,27 +55575,32 @@ async function startEc2Instance(label, githubRegistrationToken) {

const userData = buildUserDataScript(githubRegistrationToken, label);

const params = {
ImageId: config.input.ec2ImageId,
InstanceType: config.input.ec2InstanceType,
MinCount: 1,
MaxCount: 1,
UserData: Buffer.from(userData.join('\n')).toString('base64'),
SubnetId: config.input.subnetId,
SecurityGroupIds: [config.input.securityGroupId],
IamInstanceProfile: { Name: config.input.iamRoleName },
TagSpecifications: config.tagSpecifications,
};

try {
const result = await ec2.runInstances(params).promise();
const ec2InstanceId = result.Instances[0].InstanceId;
core.info(`AWS EC2 instance ${ec2InstanceId} is started`);
return ec2InstanceId;
} catch (error) {
core.error('AWS EC2 instance starting error');
throw error;
const subnetId = config.input.subnetId;
const subnets = subnetId ? subnetId.replace(/\s/g, '').split(',') : [null];

for (const subnet of subnets) {
const params = {
ImageId: config.input.ec2ImageId,
InstanceType: config.input.ec2InstanceType,
MinCount: 1,
MaxCount: 1,
UserData: Buffer.from(userData.join('\n')).toString('base64'),
SubnetId: subnet,
SecurityGroupIds: [config.input.securityGroupId],
IamInstanceProfile: { Name: config.input.iamRoleName },
TagSpecifications: config.tagSpecifications,
};
try {
const result = await ec2.runInstances(params).promise();
const ec2InstanceId = result.Instances[0].InstanceId;
core.info(`AWS EC2 instance ${ec2InstanceId} is started`);
return ec2InstanceId;
} catch (error) {
core.warning('AWS EC2 instance starting error');
core.warning(error);
}
}
core.setFailed(`Failed to launch instance after trying in ${subnets.length} subnets.`);
}

async function terminateEc2Instance() {
Expand Down
43 changes: 24 additions & 19 deletions src/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,32 @@ async function startEc2Instance(label, githubRegistrationToken) {

const userData = buildUserDataScript(githubRegistrationToken, label);

const params = {
ImageId: config.input.ec2ImageId,
InstanceType: config.input.ec2InstanceType,
MinCount: 1,
MaxCount: 1,
UserData: Buffer.from(userData.join('\n')).toString('base64'),
SubnetId: config.input.subnetId,
SecurityGroupIds: [config.input.securityGroupId],
IamInstanceProfile: { Name: config.input.iamRoleName },
TagSpecifications: config.tagSpecifications,
};
const subnetId = config.input.subnetId;
const subnets = subnetId ? subnetId.replace(/\s/g, '').split(',') : [null];

try {
const result = await ec2.runInstances(params).promise();
const ec2InstanceId = result.Instances[0].InstanceId;
core.info(`AWS EC2 instance ${ec2InstanceId} is started`);
return ec2InstanceId;
} catch (error) {
core.error('AWS EC2 instance starting error');
throw error;
for (const subnet of subnets) {
const params = {
ImageId: config.input.ec2ImageId,
InstanceType: config.input.ec2InstanceType,
MinCount: 1,
MaxCount: 1,
UserData: Buffer.from(userData.join('\n')).toString('base64'),
SubnetId: subnet,
SecurityGroupIds: [config.input.securityGroupId],
IamInstanceProfile: { Name: config.input.iamRoleName },
TagSpecifications: config.tagSpecifications,
};
try {
const result = await ec2.runInstances(params).promise();
const ec2InstanceId = result.Instances[0].InstanceId;
core.info(`AWS EC2 instance ${ec2InstanceId} is started`);
return ec2InstanceId;
} catch (error) {
core.warning('AWS EC2 instance starting error');
core.warning(error);
}
}
core.setFailed(`Failed to launch instance after trying in ${subnets.length} subnets.`);
}

async function terminateEc2Instance() {
Expand Down