diff --git a/README.md b/README.md index e27c6c2a..8fe30ba0 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ Now you're ready to go! | `iam-role-name` | Optional. Used only with the `start` mode. | IAM role name to attach to the created EC2 runner.

This allows the runner to have permissions to run additional actions within the AWS account, without having to manage additional GitHub secrets and AWS users.

Setting this requires additional AWS permissions for the role launching the instance (see above). | | `aws-resource-tags` | Optional. Used only with the `start` mode. | Specifies tags to add to the EC2 instance and any attached storage.

This field is a stringified JSON array of tag objects, each containing a `Key` and `Value` field (see example below).

Setting this requires additional AWS permissions for the role launching the instance (see above). | | `runner-home-dir` | Optional. Used only with the `start` mode. | Specifies a directory where pre-installed actions-runner software and scripts are located.

| +| `ec2-launch-template` | Optional. Used only with the `start` mode. | Specifies an existing EC2 launch template (by name), which can be used to define image ID, instance type, subnet ID, security group IDs, spot options etc

| ### Environment variables diff --git a/action.yml b/action.yml index 0cea738b..493ba245 100644 --- a/action.yml +++ b/action.yml @@ -65,6 +65,10 @@ inputs: description: >- Directory that contains actions-runner software and scripts. E.g. /home/runner/actions-runner. required: false + ec2-launch-template: + description: >- + EC2 launch template name. A launch template may be used to specify AMI, instance type etc parameters + required: false outputs: label: description: >- diff --git a/src/aws.js b/src/aws.js index 028dca42..92d16951 100644 --- a/src/aws.js +++ b/src/aws.js @@ -47,6 +47,12 @@ async function startEc2Instance(label, githubRegistrationToken) { TagSpecifications: config.tagSpecifications, }; + if (config.input.ec2LaunchTemplate) { + params.LaunchTemplate = { + LaunchTemplateName: config.input.ec2LaunchTemplate + }; + } + try { const result = await ec2.runInstances(params).promise(); const ec2InstanceId = result.Instances[0].InstanceId; diff --git a/src/config.js b/src/config.js index 13bf86a1..d2590601 100644 --- a/src/config.js +++ b/src/config.js @@ -14,6 +14,7 @@ class Config { ec2InstanceId: core.getInput('ec2-instance-id'), iamRoleName: core.getInput('iam-role-name'), runnerHomeDir: core.getInput('runner-home-dir'), + ec2LaunchTemplate: core.getInput('ec2-launch-template'), }; const tags = JSON.parse(core.getInput('aws-resource-tags')); @@ -43,7 +44,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]; + 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') {