Skip to content

Commit df3e205

Browse files
feat: add option to set placement group in launch template
1 parent f1d156e commit df3e205

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ module "runners" {
209209
metadata_options = var.runner_metadata_options
210210
credit_specification = var.runner_credit_specification
211211
cpu_options = var.runner_cpu_options
212+
placement = var.runner_placement
212213

213214
enable_runner_binaries_syncer = var.enable_runner_binaries_syncer
214215
lambda_s3_bucket = var.lambda_s3_bucket

modules/multi-runner/runners.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module "runners" {
5757
metadata_options = each.value.runner_config.runner_metadata_options
5858
credit_specification = each.value.runner_config.credit_specification
5959
cpu_options = each.value.runner_config.cpu_options
60+
placement = each.value.runner_config.placement
6061

6162
enable_runner_binaries_syncer = each.value.runner_config.enable_runner_binaries_syncer
6263
lambda_s3_bucket = var.lambda_s3_bucket

modules/multi-runner/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ variable "multi_runner_config" {
130130
core_count = number
131131
threads_per_core = number
132132
}), null)
133+
placement = optional(object({
134+
affinity = optional(string)
135+
availability_zone = optional(string)
136+
group_id = optional(string)
137+
group_name = optional(string)
138+
host_id = optional(string)
139+
host_resource_group_arn = optional(number)
140+
spread_domain = optional(string)
141+
tenancy = optional(string)
142+
partition_number = optional(number)
143+
}), null)
133144
runner_log_files = optional(list(object({
134145
log_group_name = string
135146
prefix_log_group = bool

modules/runners/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ resource "aws_launch_template" "runner" {
169169
}
170170
}
171171

172+
dynamic "placement" {
173+
for_each = var.placement != null ? [var.placement] : []
174+
content {
175+
affinity = try(placement.value.affinity, null)
176+
availability_zone = try(placement.value.availability_zone, null)
177+
group_id = try(placement.value.group_id, null)
178+
group_name = try(placement.value.group_name, null)
179+
host_id = try(placement.value.host_id, null)
180+
host_resource_group_arn = try(placement.value.host_resource_group_arn, null)
181+
spread_domain = try(placement.value.spread_domain, null)
182+
tenancy = try(placement.value.tenancy, null)
183+
partition_number = try(placement.value.partition_number, null)
184+
}
185+
}
186+
172187
monitoring {
173188
enabled = var.enable_runner_detailed_monitoring
174189
}

modules/runners/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,22 @@ variable "cpu_options" {
671671
default = null
672672
}
673673

674+
variable "placement" {
675+
description = "The placement options for the instance. See https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template#placement for details."
676+
type = object({
677+
affinity = optional(string)
678+
availability_zone = optional(string)
679+
group_id = optional(string)
680+
group_name = optional(string)
681+
host_id = optional(string)
682+
host_resource_group_arn = optional(number)
683+
spread_domain = optional(string)
684+
tenancy = optional(string)
685+
partition_number = optional(number)
686+
})
687+
default = null
688+
}
689+
674690
variable "enable_jit_config" {
675691
description = "Overwrite the default behavior for JIT configuration. By default JIT configuration is enabled for ephemeral runners and disabled for non-ephemeral runners. In case of GHES check first if the JIT config API is available. In case you are upgrading from 3.x to 4.x you can set `enable_jit_config` to `false` to avoid a breaking change when having your own AMI."
676692
type = bool

variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,22 @@ variable "runner_cpu_options" {
888888
default = null
889889
}
890890

891+
variable "runner_placement" {
892+
description = "The placement options for the instance. See https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template#placement for details."
893+
type = object({
894+
affinity = optional(string)
895+
availability_zone = optional(string)
896+
group_id = optional(string)
897+
group_name = optional(string)
898+
host_id = optional(string)
899+
host_resource_group_arn = optional(number)
900+
spread_domain = optional(string)
901+
tenancy = optional(string)
902+
partition_number = optional(number)
903+
})
904+
default = null
905+
}
906+
891907
variable "enable_jit_config" {
892908
description = "Overwrite the default behavior for JIT configuration. By default JIT configuration is enabled for ephemeral runners and disabled for non-ephemeral runners. In case of GHES check first if the JIT config API is available. In case you are upgrading from 3.x to 4.x you can set `enable_jit_config` to `false` to avoid a breaking change when having your own AMI."
893909
type = bool

0 commit comments

Comments
 (0)