Skip to content

Ubuntu custom AMI example

This module shows how to create GitHub action runners using a prebuilt AMI for the runners.

  • Configured to run with org level runners.
  • GitHub runner binary syncer is not deployed.

@@ Usages

Packer Image

You will need to build your image. This example deployment uses the image example in /images/linux-amz2. You must build this image with packer in your AWS account first. Once you have built this you need to provider your owner ID as a variable

Deploy

To use your image in the terraform modules you will need to set some values on the module.

Assuming you have built the linux-al2023 image which has a pre-defined AMI name in the following format github-runner-al2023-x86_64-YYYYMMDDhhmm you can use the following values.

module "runners" {
  ...
  # set the name of the ami to use
  ami_filter        = { name = ["github-runner-al2023-x86_64-2023*"], state = ["available"] }
  # provide the owner id of
  ami_owners        = ["<your owner id>"]

  enable_userdata = false
  ...
}

If your owner is the same as the account you are logging into then you can use aws_caller_identity to retrieve it dynamically.

data "aws_caller_identity" "current" {}

module "runners" {
  ...
  ami_owners       = [data.aws_caller_identity.current.account_id]
  ...
}

You can then deploy the terraform

terraform init
terraform apply

The module will try to update the GitHub App webhook and secret (only linux/mac). You can receive the webhook details by running:

terraform output webhook_secret

Requirements

Name Version
terraform >= 1.3.0
aws ~> 5.27
local ~> 2.0
random ~> 3.0

Providers

Name Version
aws 5.31.0
random 3.6.0

Modules

Name Source Version
base ../base n/a
runners ../../ n/a
webhook_github_app ../../modules/webhook-github-app n/a

Resources

Name Type
random_id.random resource
aws_caller_identity.current data source

Inputs

Name Description Type Default Required
ami_name_filter AMI name filter for the action runner AMI. By default amazon linux 2 is used. string "github-runner-al2023-x86_64-*" no
github_app GitHub for API usages.
object({
id = string
key_base64 = string
})
n/a yes
runner_os The EC2 Operating System type to use for action runner instances (linux,windows). string "linux" no

Outputs

Name Description
webhook_endpoint n/a
webhook_secret n/a