Skip to content

Commit 090c116

Browse files
committed
feat: allow setting VPC and subnets per runner
1 parent ca425da commit 090c116

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

examples/multi-runner/main.tf

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@ 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 = {
7+
for c in fileset("${path.module}/templates/runner-configs", "*.yaml") :
8+
9+
trimsuffix(c, ".yaml") => yamldecode(
10+
templatefile(
11+
"${path.module}/templates/runner-configs/${c}",
12+
{
13+
vpc_id = module.base_other.vpc.vpc_id
14+
subnet_ids = jsonencode(module.base_other.vpc.private_subnets)
15+
}
16+
)
17+
)
18+
}
719
}
820

921
resource "random_id" "random" {
@@ -16,6 +28,13 @@ module "base" {
1628
aws_region = local.aws_region
1729
}
1830

31+
module "base_other" {
32+
source = "../base"
33+
34+
prefix = "${local.environment}-other"
35+
aws_region = local.aws_region
36+
}
37+
1938
module "multi-runner" {
2039
source = "../../modules/multi-runner"
2140
multi_runner_config = local.multi_runner_config

examples/multi-runner/templates/runner-configs/linux-x64.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ runner_config:
1010
runner_extra_labels: amazon
1111
runner_name_prefix: amazon-x64_
1212
enable_ssm_on_runners: true
13+
vpc_id: ${vpc_id}
14+
subnet_ids: ${subnet_ids}
1315
instance_types:
1416
- m5ad.large
1517
- m5a.large

modules/multi-runner/README.md

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

modules/multi-runner/runners.tf

Lines changed: 2 additions & 2 deletions
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.vpc_id, var.vpc_id)
7+
subnet_ids = coalesce(each.value.subnet_ids, var.subnet_ids)
88
prefix = "${var.prefix}-${each.key}"
99
tags = merge(local.tags, {
1010
"ghr:environment" = "${var.prefix}-${each.key}"

modules/multi-runner/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ variable "multi_runner_config" {
7676
userdata_post_install = optional(string, "")
7777
runner_ec2_tags = optional(map(string), {})
7878
runner_iam_role_managed_policy_arns = optional(list(string), [])
79+
vpc_id = optional(string, null)
80+
subnet_ids = optional(list(string), null)
7981
idle_config = optional(list(object({
8082
cron = string
8183
timeZone = string
@@ -172,6 +174,8 @@ variable "multi_runner_config" {
172174
userdata_post_install: "Script to be ran after the GitHub Actions runner is installed on the EC2 instances"
173175
runner_ec2_tags: "Map of tags that will be added to the launch template instance tag specifications."
174176
runner_iam_role_managed_policy_arns: "Attach AWS or customer-managed IAM policies (by ARN) to the runner IAM role"
177+
vpc_id: "The VPC for security groups of the action runners. If not set uses the value of `var.vpc_id`."
178+
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`."
175179
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."
176180
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."
177181
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)