Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 1288c81

Browse files
taharahnpalm
andauthored
feat: allow setting VPC and subnets per runner (#3467)
This allows passing in a different VPC and subnet IDs for each runner config and falling back to the "global" value set via the existing `vpc_id` and `subnet_ids` variables. --------- Co-authored-by: Niek Palm <[email protected]>
1 parent 1c87fc5 commit 1288c81

File tree

17 files changed

+109
-17
lines changed

17 files changed

+109
-17
lines changed

Diff for: .terraform.lock.hcl

+45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/arm64/.terraform.lock.hcl

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/base/.terraform.lock.hcl

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/default/.terraform.lock.hcl

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/ephemeral/.terraform.lock.hcl

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/lambdas-download/.terraform.lock.hcl

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/multi-runner/.terraform.lock.hcl

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/multi-runner/main.tf

+21-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,27 @@ locals {
33
aws_region = "eu-west-1"
44

55
# 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}")) }
6+
multi_runner_config_files = {
7+
for c in fileset("${path.module}/templates/runner-configs", "*.yaml") :
8+
9+
trimsuffix(c, ".yaml") => yamldecode(file("${path.module}/templates/runner-configs/${c}"))
10+
}
11+
multi_runner_config = {
12+
for k, v in local.multi_runner_config_files :
13+
14+
k => merge(
15+
v,
16+
{
17+
runner_config = merge(
18+
v.runner_config,
19+
{
20+
subnet_ids = lookup(v.runner_config, "subnet_ids", null) != null ? [module.base.vpc.private_subnets[0]] : null
21+
vpc_id = lookup(v.runner_config, "vpc_id", null) != null ? module.base.vpc.vpc_id : null
22+
}
23+
)
24+
}
25+
)
26+
}
727
}
828

929
resource "random_id" "random" {

Diff for: examples/multi-runner/templates/runner-configs/linux-x64.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ runner_config:
99
runner_architecture: x64
1010
runner_name_prefix: amazon-x64_
1111
enable_ssm_on_runners: true
12+
vpc_id: ${vpc_id}
13+
subnet_ids: ${subnet_ids}
1214
instance_types:
1315
- m5ad.large
1416
- m5a.large

Diff for: examples/permissions-boundary/.terraform.lock.hcl

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/permissions-boundary/setup/main.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ data "aws_caller_identity" "current" {}
33
module "iam" {
44
source = "../../../modules/setup-iam-permissions"
55

6-
environment = "boundaries"
7-
account_id = data.aws_caller_identity.current.account_id
6+
account_id = data.aws_caller_identity.current.account_id
87

98
namespaces = {
109
boundary_namespace = "boundaries"

Diff for: examples/prebuilt/.terraform.lock.hcl

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/ubuntu/.terraform.lock.hcl

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/windows/.terraform.lock.hcl

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: modules/multi-runner/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ For each configuration:
1111
- When enabled, the [distribution syncer](https://philips-labs.github.io/terraform-aws-github-runner/modules/internal/runner-binaries-syncer/) is deployed for each unique combination of OS and architecture.
1212
- For each configuration a queue is created and [runner module](https://philips-labs.github.io/terraform-aws-github-runner/modules/internal/runners/) is deployed
1313

14-
1514
## Matching
1615

1716
Matching of the configuration is done based on the labels specified in labelMatchers configuration. The webhook is processing the `workflow_job` event and match the labels against the labels specified in labelMatchers configuration in the order of configuration with exact-match true first, followed by all exact matches false.
1817

19-
2018
## The catch
2119

2220
Controlling which event is taken up by which runner is not to this module. It is completely done by GitHub. This means when potentially different runners can run the same job there is nothing that can be done to guarantee a certain runner will take up the job.
@@ -30,7 +28,6 @@ Jobs not defining all all labels but for example only `[self-hosted, linux]` cou
3028

3129
A complete example is available in the examples, see the [multi-runner example](https://philips-labs.github.io/terraform-aws-github-runner/examples/) for actual implementation.
3230

33-
3431
```hcl
3532
3633
module "multi-runner" {

Diff for: modules/multi-runner/runners.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module "runners" {
33
for_each = local.runner_config
44
aws_region = var.aws_region
55
aws_partition = var.aws_partition
6-
vpc_id = var.vpc_id
7-
subnet_ids = var.subnet_ids
6+
vpc_id = coalesce(each.value.runner_config.vpc_id, var.vpc_id)
7+
subnet_ids = coalesce(each.value.runner_config.subnet_ids, var.subnet_ids)
88
prefix = "${var.prefix}-${each.key}"
99
tags = merge(local.tags, {
1010
"ghr:environment" = "${var.prefix}-${each.key}"

Diff for: modules/multi-runner/variables.tf

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ variable "multi_runner_config" {
7878
userdata_post_install = optional(string, "")
7979
runner_ec2_tags = optional(map(string), {})
8080
runner_iam_role_managed_policy_arns = optional(list(string), [])
81+
vpc_id = optional(string, null)
82+
subnet_ids = optional(list(string), null)
8183
idle_config = optional(list(object({
8284
cron = string
8385
timeZone = string
@@ -169,6 +171,8 @@ variable "multi_runner_config" {
169171
userdata_post_install: "Script to be ran after the GitHub Actions runner is installed on the EC2 instances"
170172
runner_ec2_tags: "Map of tags that will be added to the launch template instance tag specifications."
171173
runner_iam_role_managed_policy_arns: "Attach AWS or customer-managed IAM policies (by ARN) to the runner IAM role"
174+
vpc_id: "The VPC for security groups of the action runners. If not set uses the value of `var.vpc_id`."
175+
subnet_ids: "List of subnets in which the action runners will be launched, the subnets needs to be subnets in the `vpc_id`. If not set, uses the value of `var.subnet_ids`."
172176
idle_config: "List of time period that can be defined as cron expression to keep a minimum amount of runners active instead of scaling down to 0. By defining this list you can ensure that in time periods that match the cron expression within 5 seconds a runner is kept idle."
173177
runner_log_files: "(optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details."
174178
block_device_mappings: "The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops`, `throughput`, `kms_key_id`, `snapshot_id`."

0 commit comments

Comments
 (0)