Skip to content

Commit 08c881d

Browse files
committed
feat: allow setting VPC and subnets per runner
1 parent 57f056d commit 08c881d

File tree

5 files changed

+125
-101
lines changed

5 files changed

+125
-101
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" {
@@ -17,6 +29,13 @@ module "base" {
1729
aws_region = local.aws_region
1830
}
1931

32+
module "base_other" {
33+
source = "../base"
34+
35+
prefix = "${local.environment}-other"
36+
aws_region = local.aws_region
37+
}
38+
2039
module "runners" {
2140
source = "../../modules/multi-runner"
2241
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
@@ -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

modules/multi-runner/README.md

Lines changed: 97 additions & 98 deletions
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
@@ -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)