Skip to content

Commit 2b0e233

Browse files
committed
Major upgrade, ongoing
1 parent 8c6dc7f commit 2b0e233

33 files changed

+419
-106
lines changed

examples/multi-runner-cppal/README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
This module shows how to create GitHub action runners with multiple runner configuration together in one deployment. This example has the configurations for the following runner types with the relevant labels supported by them as matchers:
44

5-
- Linux ARM64 `["self-hosted", "linux", "arm64", "amazon"]`
6-
- Linux Ubuntu `["self-hosted", "linux", "x64", "ubuntu-latest"]` or `["self-hosted", "linux", "x64", "ubuntu-2204"]``
7-
- Linux X64 `["self-hosted", "linux", "x64", "amazon"]`
8-
- Windows X64 `["self-hosted", "windows", "x64", "servercore-2022"]`
5+
- Linux ARM64 `["self-hosted", "linux", "arm64", "amazon"]`: Amazon Linux ARM64 non ephemeral runner based on module defaults
6+
- Linux Ubuntu 24.04 `["self-hosted", "linux", "x64", "ubuntu-latest"]` or `["self-hosted", "linux", "x64", "ubuntu-2404"]`: Ubuntu runners non ephemeral based on a custom start script.
7+
- Linux Ubuntu 22.04 `["self-hosted", "linux", "x64", "ubuntu-2204"]`: Ubuntu runners non ephemeral based on a custom start script.
8+
- Linux X64 `["self-hosted", "linux", "x64", "amazon"]`: Amazon X64 Linux runners ephemeral with retry enabled.
9+
- Windows X64 `["self-hosted", "windows", "x64", "servercore-2022"]`: Windows X64 Servercore 2022 runners non ephemeral based on a custom start script.
910

1011
The module will decide the runner for the workflow job based on the match in the labels defined in the workflow job and runner configuration. Also the runner configuration allows the match to be exact or non-exact match. We recommend to use only exact matches.
1112

@@ -21,9 +22,9 @@ Per combination of OS and architecture a lambda distribution syncer will be crea
2122

2223
## Usages
2324

24-
Steps for the full setup, such as creating a GitHub app can be found in the root module's [README](../../README.md). First download the Lambda releases from GitHub. Alternatively you can build the lambdas locally with Node or Docker, there is a simple build script in `<root>/.ci/build.sh`. In the `main.tf` you can simply remove the location of the lambda zip files, the default location will work in this case.
25+
Steps for the full setup, such as creating a GitHub app can be found the [docs](https://github-aws-runners.github.io/terraform-aws-github-runner/). First download the Lambda releases from GitHub. Alternatively you can build the lambdas locally with Node or Docker, there is a simple build script in `<root>/.ci/build.sh`. In the `main.tf` you can simply remove the location of the lambda zip files, the default location will work in this case.
2526

26-
> Ensure you have set the version in `lambdas-download/main.tf` for running the example. The version needs to be set to a GitHub release version, see https://github.com/philips-labs/terraform-aws-github-runner/releases
27+
> The default example assumes local built lambda's available. Ensure you have built the lambda's. Alternatively you can download the lambda's. The version needs to be set to a GitHub release version, see https://github.com/github-aws-runners/terraform-aws-github-runner/releases
2728
2829
```bash
2930
cd ../lambdas-download
@@ -32,61 +33,68 @@ terraform apply -var=module_version=<VERSION>
3233
cd -
3334
```
3435

35-
Before running Terraform, ensure the GitHub app is configured. See the [configuration details](../../README.md#usages) for more details.
36+
37+
Before running Terraform, ensure the GitHub app is configured. See the [configuration details](https://github-aws-runners.github.io/terraform-aws-github-runner/configuration/) for more details.
3638

3739
```bash
3840
terraform init
3941
terraform apply
4042
```
4143

42-
You can receive the webhook details by running:
44+
The example will try to update the webhook of your GitHub. In case the update fails the apply will not fail. You can receive the webhook details by running:
4345

4446
```bash
4547
terraform output -raw webhook_secret
4648
```
4749

48-
Be-aware some shells will print some end of line character `%`.
49-
5050
<!-- BEGIN_TF_DOCS -->
5151
## Requirements
5252

5353
| Name | Version |
5454
|------|---------|
5555
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
56-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.0 |
56+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5.27 |
5757
| <a name="requirement_local"></a> [local](#requirement\_local) | ~> 2.0 |
5858
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.0 |
5959

6060
## Providers
6161

6262
| Name | Version |
6363
|------|---------|
64-
| <a name="provider_random"></a> [random](#provider\_random) | 3.4.3 |
64+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.82.1 |
65+
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.3 |
6566

6667
## Modules
6768

6869
| Name | Source | Version |
6970
|------|--------|---------|
70-
| <a name="module_multi-runner"></a> [multi-runner](#module\_multi-runner) | ../../modules/multi-runner | n/a |
71-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | 3.11.2 |
71+
| <a name="module_base"></a> [base](#module\_base) | ../base | n/a |
72+
| <a name="module_runners"></a> [runners](#module\_runners) | ../../modules/multi-runner | n/a |
73+
| <a name="module_webhook_github_app"></a> [webhook\_github\_app](#module\_webhook\_github\_app) | ../../modules/webhook-github-app | n/a |
7274

7375
## Resources
7476

7577
| Name | Type |
7678
|------|------|
79+
| [aws_ssm_parameter.al2023_arm64](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
7780
| [random_id.random](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
81+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
82+
| [aws_ssm_parameter.al2023_arm64](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssm_parameter) | data source |
83+
| [aws_ssm_parameter.al2023_x64](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssm_parameter) | data source |
7884

7985
## Inputs
8086

8187
| Name | Description | Type | Default | Required |
8288
|------|-------------|------|---------|:--------:|
83-
| <a name="input_environment"></a> [environment](#input\_environment) | n/a | `string` | `null` | no |
84-
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br> id = string<br> key_base64 = string<br> })</pre> | n/a | yes |
89+
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region to deploy to | `string` | `"eu-west-1"` | no |
90+
| <a name="input_environment"></a> [environment](#input\_environment) | Environment name, used as prefix | `string` | `null` | no |
91+
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |
8592

8693
## Outputs
8794

8895
| Name | Description |
8996
|------|-------------|
97+
| <a name="output_deprecated_variables_warning"></a> [deprecated\_variables\_warning](#output\_deprecated\_variables\_warning) | n/a |
9098
| <a name="output_webhook_endpoint"></a> [webhook\_endpoint](#output\_webhook\_endpoint) | n/a |
9199
| <a name="output_webhook_secret"></a> [webhook\_secret](#output\_webhook\_secret) | n/a |
92-
<!-- END_TF_DOCS -->
100+
<!-- END_TF_DOCS -->

examples/multi-runner-cppal/main.tf

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,69 @@
1+
# The module provides several ways to chose the AMI ID for the runners. The recommended way is to use the SSM parameter ARN.
2+
# The default is (still) a build in filter that creates internally an SSM parameter for the AMI ID.
3+
#
4+
# Here we show two other options
5+
# 1. Use the SSM parameter ARN directly via a public available SSM parameter
6+
# 2. Use the SSM parameter ARN via a private SSM parameter injected to the module
7+
# 3. Other runners like ubuntu, windows, etc. are using the build in one parameter.
8+
9+
data "aws_ssm_parameter" "al2023_x64" {
10+
name = "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64"
11+
}
12+
13+
data "aws_ssm_parameter" "al2023_arm64" {
14+
name = "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-arm64"
15+
}
16+
17+
resource "aws_ssm_parameter" "al2023_arm64" {
18+
name = local.al2023_arm64_name
19+
type = "String"
20+
data_type = "aws:ec2:image"
21+
value = data.aws_ssm_parameter.al2023_arm64.value
22+
}
23+
24+
data "aws_caller_identity" "current" {}
25+
126
locals {
227
environment = var.environment != null ? var.environment : "gha"
328
aws_region = var.aws_region
429

30+
# create map only with amazon linux 2023 x64 and arm64 to overwrite the default
31+
al2023_arm64_name = "/examples/multi-runner/aws-github-runners/ami/amazon-linux-2023-arm64"
32+
ssm_ami_arns = {
33+
"linux-x64" = data.aws_ssm_parameter.al2023_x64.arn
34+
# construct the arn to avoid terraform count errors
35+
"linux-arm64" = "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter${local.al2023_arm64_name}"
36+
}
37+
538
# Load runner configurations from Yaml files
6-
multi_runner_config = { for c in fileset("${path.module}/templates/runner-configs", "*.yaml") : trimsuffix(c, ".yaml") => yamldecode(file("${path.module}/templates/runner-configs/${c}")) }
39+
multi_runner_config_files = {
40+
for c in fileset("${path.module}/templates/runner-configs", "*.yaml") :
41+
42+
trimsuffix(c, ".yaml") => yamldecode(file("${path.module}/templates/runner-configs/${c}"))
43+
}
44+
45+
multi_runner_config = {
46+
for k, v in local.multi_runner_config_files :
47+
48+
k => merge(
49+
v,
50+
{
51+
runner_config = merge(
52+
v.runner_config,
53+
{
54+
subnet_ids = lookup(v.runner_config, "subnet_ids", null) != null ? [module.base.vpc.private_subnets[0]] : null
55+
vpc_id = lookup(v.runner_config, "vpc_id", null) != null ? module.base.vpc.vpc_id : null
56+
ami = contains(keys(v.runner_config), "ami") ? merge(
57+
v.runner_config.ami,
58+
{
59+
id_ssm_parameter_arn = lookup(local.ssm_ami_arns, k, null) != null ? local.ssm_ami_arns[k] : null
60+
}
61+
) : null
62+
}
63+
)
64+
}
65+
)
66+
}
767
}
868

969
resource "random_id" "random" {
@@ -17,7 +77,7 @@ module "base" {
1777
aws_region = local.aws_region
1878
}
1979

20-
module "multi-runner" {
80+
module "runners" {
2181
source = "../../modules/multi-runner"
2282
multi_runner_config = local.multi_runner_config
2383
# Alternative to loading runner configuration from Yaml files is using static configuration:
@@ -27,7 +87,6 @@ module "multi-runner" {
2787
# labelMatchers = [["self-hosted", "linux", "x64", "amazon"]]
2888
# exactMatch = false
2989
# }
30-
# fifo = true
3190
# delay_webhook_event = 0
3291
# runner_config = {
3392
# runner_os = "linux"
@@ -36,7 +95,7 @@ module "multi-runner" {
3695
# create_service_linked_role_spot = true
3796
# enable_ssm_on_runners = true
3897
# instance_types = ["m5ad.large", "m5a.large"]
39-
# runner_extra_labels = "amazon"
98+
# runner_extra_labels = ["amazon"]
4099
# runners_maximum_count = 1
41100
# enable_ephemeral_runners = true
42101
# scale_down_schedule_expression = "cron(* * * * ? *)"
@@ -59,15 +118,52 @@ module "multi-runner" {
59118
webhook_secret = random_id.random.hex
60119
}
61120

121+
# Deploy webhook using the EventBridge
122+
eventbridge = {
123+
enable = true
124+
# adjust the allow events to only allow specific events, like workflow_job
125+
accept_events = ["workflow_job"]
126+
}
127+
128+
# enable this section for tracing
129+
# tracing_config = {
130+
# mode = "Active"
131+
# capture_error = true
132+
# capture_http_requests = true
133+
# }
62134
# Assuming local build lambda's to use pre build ones, uncomment the lines below and download the
63135
# lambda zip files lambda_download
64136
webhook_lambda_zip = "../lambdas-download-cppal/webhook.zip"
65137
runner_binaries_syncer_lambda_zip = "../lambdas-download-cppal/runner-binaries-syncer.zip"
66138
runners_lambda_zip = "../lambdas-download-cppal/runners.zip"
67139

68-
# enable_workflow_job_events_queue = true
69-
# override delay of events in seconds
70-
71140
# Enable debug logging for the lambda functions
72141
# log_level = "debug"
142+
143+
# Enable to track the spot instance termination warning
144+
# instance_termination_watcher = {
145+
# enable = true
146+
# }
147+
148+
# Enable metrics
149+
# metrics = {
150+
# enable = true
151+
# metric = {
152+
# enable_github_app_rate_limit = true
153+
# enable_job_retry = false
154+
# enable_spot_termination_warning = true
155+
# }
156+
# }
157+
}
158+
159+
module "webhook_github_app" {
160+
source = "../../modules/webhook-github-app"
161+
depends_on = [module.runners]
162+
163+
github_app = {
164+
key_base64 = var.github_app.key_base64
165+
id = var.github_app.id
166+
webhook_secret = random_id.random.hex
167+
}
168+
webhook_endpoint = module.runners.webhook.endpoint
73169
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
output "webhook_endpoint" {
2-
value = module.multi-runner.webhook.endpoint
2+
value = module.runners.webhook.endpoint
33
}
44

55
output "webhook_secret" {
66
sensitive = true
77
value = random_id.random.hex
88
}
9+
10+
output "deprecated_variables_warning" {
11+
value = join("", [
12+
module.runners.deprecated_variables_warning,
13+
])
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
provider "aws" {
22
region = local.aws_region
3+
4+
default_tags {
5+
tags = {
6+
Example = local.environment
7+
}
8+
}
39
}

examples/multi-runner-cppal/templates/runner-configs/ubuntu-bionic-arm64.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ runner_config:
1515
enable_userdata: false
1616
runner_os: linux
1717
runner_architecture: arm64
18-
runner_extra_labels: "ubuntu-18.04-aws"
18+
runner_extra_labels: ["ubuntu-18.04-aws"]
1919
runner_run_as: ubuntu
2020
runner_name_prefix: ubuntu-1804-arm64_
2121
enable_ssm_on_runners: true
@@ -27,8 +27,9 @@ runner_config:
2727
delay_webhook_event: 0
2828
scale_down_schedule_expression: cron(* * * * ? *)
2929
# userdata_template: ./templates/user-data.sh
30-
ami_owners: [ "047402373783" ]
31-
ami_filter: { 'name': ['github-runner-ubuntu-bionic-arm64-202410151633'] }
30+
ami:
31+
owners: [ "047402373783" ]
32+
filter: { 'name': ['github-runner-ubuntu-bionic-arm64-202410151633'] }
3233
block_device_mappings:
3334
- device_name: /dev/sda1
3435
delete_on_termination: true

examples/multi-runner-cppal/templates/runner-configs/ubuntu-bionic.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ runner_config:
1515
enable_userdata: false
1616
runner_os: linux
1717
runner_architecture: x64
18-
runner_extra_labels: "ubuntu-18.04-aws"
18+
runner_extra_labels: ["ubuntu-18.04-aws"]
1919
runner_run_as: ubuntu
2020
runner_name_prefix: ubuntu-1804-x64_
2121
enable_ssm_on_runners: true
@@ -27,8 +27,9 @@ runner_config:
2727
delay_webhook_event: 0
2828
scale_down_schedule_expression: cron(* * * * ? *)
2929
# userdata_template: ./templates/user-data.sh
30-
ami_owners: [ "047402373783" ]
31-
ami_filter: { 'name': ['github-runner-ubuntu-bionic-amd64-202411261305'] }
30+
ami:
31+
owners: [ "047402373783" ]
32+
filter: { 'name': ['github-runner-ubuntu-bionic-amd64-202411261305'] }
3233
block_device_mappings:
3334
- device_name: /dev/sda1
3435
delete_on_termination: true

examples/multi-runner-cppal/templates/runner-configs/ubuntu-focal-arm64.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ runner_config:
1515
enable_userdata: false
1616
runner_os: linux
1717
runner_architecture: arm64
18-
runner_extra_labels: "ubuntu-20.04-aws"
18+
runner_extra_labels: ["ubuntu-20.04-aws"]
1919
runner_run_as: ubuntu
2020
runner_name_prefix: ubuntu-2004-arm64_
2121
enable_ssm_on_runners: true
@@ -27,8 +27,9 @@ runner_config:
2727
delay_webhook_event: 0
2828
scale_down_schedule_expression: cron(* * * * ? *)
2929
# userdata_template: ./templates/user-data.sh
30-
ami_owners: [ "047402373783" ]
31-
ami_filter: { 'name': ['github-runner-ubuntu-focal-arm64-202410151633'] }
30+
ami:
31+
owners: [ "047402373783" ]
32+
filter: { 'name': ['github-runner-ubuntu-focal-arm64-202410151633'] }
3233
block_device_mappings:
3334
- device_name: /dev/sda1
3435
delete_on_termination: true

examples/multi-runner-cppal/templates/runner-configs/ubuntu-focal.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ runner_config:
1515
enable_userdata: false
1616
runner_os: linux
1717
runner_architecture: x64
18-
runner_extra_labels: "ubuntu-20.04-aws"
18+
runner_extra_labels: ["ubuntu-20.04-aws"]
1919
runner_run_as: ubuntu
2020
runner_name_prefix: ubuntu-2004-x64_
2121
enable_ssm_on_runners: true
@@ -27,8 +27,9 @@ runner_config:
2727
delay_webhook_event: 0
2828
scale_down_schedule_expression: cron(* * * * ? *)
2929
# userdata_template: ./templates/user-data.sh
30-
ami_owners: [ "047402373783" ]
31-
ami_filter: { 'name': ['github-runner-ubuntu-focal-amd64-202411261305'] }
30+
ami:
31+
owners: [ "047402373783" ]
32+
filter: { 'name': ['github-runner-ubuntu-focal-amd64-202411261305'] }
3233
block_device_mappings:
3334
- device_name: /dev/sda1
3435
delete_on_termination: true

examples/multi-runner-cppal/templates/runner-configs/ubuntu-jammy-arm64.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ runner_config:
1616
enable_userdata: false
1717
runner_os: linux
1818
runner_architecture: arm64
19-
runner_extra_labels: "ubuntu-latest-aws,ubuntu-22.04-aws"
19+
runner_extra_labels: ["ubuntu-latest-aws,ubuntu-22.04-aws"]
2020
runner_run_as: ubuntu
2121
runner_name_prefix: ubuntu-2204-arm64_
2222
enable_ssm_on_runners: true
@@ -28,8 +28,9 @@ runner_config:
2828
delay_webhook_event: 0
2929
scale_down_schedule_expression: cron(* * * * ? *)
3030
# userdata_template: ./templates/user-data.sh
31-
ami_owners: [ "047402373783" ]
32-
ami_filter: { 'name': ['github-runner-ubuntu-jammy-arm64-202410151633'] }
31+
ami:
32+
owners: [ "047402373783" ]
33+
filter: { 'name': ['github-runner-ubuntu-jammy-arm64-202410151633'] }
3334
block_device_mappings:
3435
- device_name: /dev/sda1
3536
delete_on_termination: true

0 commit comments

Comments
 (0)