Skip to content

Commit 89f5e96

Browse files
committed
refactor to ami ojbject
1 parent 9a3ec9b commit 89f5e96

File tree

10 files changed

+85
-31
lines changed

10 files changed

+85
-31
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ runner_config:
1515
instance_types:
1616
- t4g.large
1717
- c6g.large
18-
ami_id_ssm_parameter_arn: ${ami_id_ssm_parameter_arn}
18+
ami:
19+
id_ssm_parameter_arn: ${ami_id_ssm_parameter_arn}
1920
runners_maximum_count: 1
2021
delay_webhook_event: 0
2122
scale_down_schedule_expression: cron(* * * * ? *)

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ runner_config:
2222
delay_webhook_event: 0
2323
scale_down_schedule_expression: cron(* * * * ? *)
2424
userdata_template: ./templates/user-data.sh
25-
ami_owners:
26-
- "099720109477" # Canonical's Amazon account ID
27-
ami_filter:
28-
name:
29-
- ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*
30-
state:
31-
- available
25+
ami:
26+
owners:
27+
- "099720109477" # Canonical's Amazon account ID
28+
filter:
29+
name:
30+
- ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*
31+
state:
32+
- available
3233
block_device_mappings:
3334
- device_name: /dev/sda1
3435
delete_on_termination: true

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ runner_config:
1414
instance_types:
1515
- m5ad.large
1616
- m5a.large
17-
ami_id_ssm_parameter_arn: ${ami_id_ssm_parameter_arn}
17+
ami:
18+
id_ssm_parameter_arn: ${ami_id_ssm_parameter_arn}
1819
runners_maximum_count: 1
1920
enable_ephemeral_runners: true
2021
enable_on_demand_failover_for_errors: ['InsufficientInstanceCapacity']

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ runner_config:
1515
delay_webhook_event: 5
1616
scale_down_schedule_expression: cron(* * * * ? *)
1717
runner_boot_time_in_minutes: 20
18-
ami_filter:
19-
name:
20-
- Windows_Server-2022-English-Full-ECS_Optimized-*
21-
state:
22-
- available
18+
ami:
19+
filter:
20+
name:
21+
- Windows_Server-2022-English-Full-ECS_Optimized-*
22+
state:
23+
- available

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ module "runners" {
178178
block_device_mappings = var.block_device_mappings
179179

180180
runner_architecture = var.runner_architecture
181+
ami = var.ami
181182
ami_filter = var.ami_filter
182183
ami_owners = var.ami_owners
183184
ami_id_ssm_parameter_arn = var.ami_id_ssm_parameter_arn

modules/multi-runner/runners.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module "runners" {
2626
block_device_mappings = each.value.runner_config.block_device_mappings
2727

2828
runner_architecture = each.value.runner_config.runner_architecture
29+
ami = each.value.runner_config.ami
2930
ami_filter = each.value.runner_config.ami_filter
3031
ami_owners = each.value.runner_config.ami_owners
3132
ami_id_ssm_parameter_arn = each.value.runner_config.ami_id_ssm_parameter_arn

modules/multi-runner/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ variable "multi_runner_config" {
6565
http_tokens = "required"
6666
http_put_response_hop_limit = 1
6767
})
68+
ami = optional(object({
69+
filter = optional(map(list(string)), { state = ["available"] })
70+
owners = optional(list(string), ["amazon"])
71+
id_ssm_parameter_name = optional(string, null)
72+
id_ssm_parameter_arn = optional(string, null)
73+
kms_key_arn = optional(string, null)
74+
}), null)
75+
# Deprecated: Use ami object instead
76+
ami = optional(object({
77+
filter = optional(map(list(string)), { state = ["available"] })
78+
owners = optional(list(string), ["amazon"])
79+
id_ssm_parameter_name = optional(string, null)
80+
id_ssm_parameter_arn = optional(string, null)
81+
kms_key_arn = optional(string, null)
82+
}), null)
83+
# Deprecated: Use ami object instead
6884
ami_filter = optional(map(list(string)), { state = ["available"] })
6985
ami_owners = optional(list(string), ["amazon"])
7086
ami_id_ssm_parameter_arn = optional(string, null)

modules/runners/main.tf

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@ locals {
3737
"linux" = "${path.module}/templates/start-runner.sh"
3838
}
3939

40-
ami_kms_key_arn = var.ami_kms_key_arn != null ? var.ami_kms_key_arn : ""
41-
ami_filter = merge(local.default_ami[var.runner_os], var.ami_filter)
42-
ami_id_ssm_module_managed = var.ami_id_ssm_parameter_arn == null
40+
# Handle AMI configuration from either the new object or old variables
41+
ami_config = var.ami != null ? var.ami : {
42+
filter = var.ami_filter
43+
owners = var.ami_owners
44+
id_ssm_parameter_name = var.ami_id_ssm_parameter_name
45+
id_ssm_parameter_arn = var.ami_id_ssm_parameter_arn
46+
kms_key_arn = var.ami_kms_key_arn
47+
}
48+
ami_kms_key_arn = local.ami_config.kms_key_arn != null ? local.ami_config.kms_key_arn : ""
49+
ami_filter = merge(local.default_ami[var.runner_os], local.ami_config.filter)
50+
ami_id_ssm_module_managed = local.ami_config.id_ssm_parameter_arn == null
4351

4452
enable_job_queued_check = var.enable_job_queued_check == null ? !var.enable_ephemeral_runners : var.enable_job_queued_check
4553

@@ -82,7 +90,7 @@ data "aws_ami" "runner" {
8290
}
8391
}
8492

85-
owners = var.ami_owners
93+
owners = local.ami_config.owners
8694
}
8795

8896
resource "aws_ssm_parameter" "runner_ami_id" {

modules/runners/variables.tf

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
variable "ami" {
2+
description = "AMI configuration for the action runner instances"
3+
type = object({
4+
filter = optional(map(list(string)), { state = ["available"] })
5+
owners = optional(list(string), ["amazon"])
6+
id_ssm_parameter_name = optional(string, null)
7+
id_ssm_parameter_arn = optional(string, null)
8+
kms_key_arn = optional(string, null)
9+
})
10+
default = null
11+
}
12+
113
variable "aws_region" {
214
description = "AWS region."
315
type = string
@@ -114,7 +126,7 @@ variable "instance_types" {
114126
}
115127

116128
variable "ami_filter" {
117-
description = "Map of lists used to create the AMI filter for the action runner AMI."
129+
description = "[DEPRECATED: Use ami.filter] Map of lists used to create the AMI filter for the action runner AMI."
118130
type = map(list(string))
119131
default = { state = ["available"] }
120132
validation {
@@ -125,25 +137,25 @@ variable "ami_filter" {
125137
}
126138

127139
variable "ami_owners" {
128-
description = "The list of owners used to select the AMI of action runner instances."
140+
description = "[DEPRECATED: Use ami.owners] The list of owners used to select the AMI of action runner instances."
129141
type = list(string)
130142
default = ["amazon"]
131143
}
132144

133145
variable "ami_id_ssm_parameter_arn" {
134-
description = "ARN of the SSM parameter (of data type aws:ec2:image) that contains the AMI ID to launch runner instances from. Overrides ami_filter"
146+
description = "[DEPRECATED: Use ami.id_ssm_parameter_arn] ARN of the SSM parameter (of data type aws:ec2:image) that contains the AMI ID to launch runner instances from. Overrides ami_filter"
135147
type = string
136148
default = null
137149
}
138150

139151
variable "ami_id_ssm_parameter_name" {
140-
description = "Externally managed SSM parameter (of data type aws:ec2:image) that contains the AMI ID to launch runner instances from. Overrides ami_filter"
152+
description = "[DEPRECATED: Use ami.id_ssm_parameter_name] Externally managed SSM parameter (of data type aws:ec2:image) that contains the AMI ID to launch runner instances from. Overrides ami_filter"
141153
type = string
142154
default = null
143155
}
144156

145157
variable "ami_kms_key_arn" {
146-
description = "Optional CMK Key ARN to be used to launch an instance from a shared encrypted AMI"
158+
description = "[DEPRECATED: Use ami.kms_key_arn] Optional CMK Key ARN to be used to launch an instance from a shared encrypted AMI"
147159
type = string
148160
default = null
149161
}

variables.tf

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,37 +366,49 @@ variable "block_device_mappings" {
366366
}]
367367
}
368368

369+
variable "ami" {
370+
description = "AMI configuration for the action runner instances"
371+
type = object({
372+
filter = optional(map(list(string)), { state = ["available"] })
373+
owners = optional(list(string), ["amazon"])
374+
id_ssm_parameter_name = optional(string, null)
375+
id_ssm_parameter_arn = optional(string, null)
376+
kms_key_arn = optional(string, null)
377+
})
378+
default = null
379+
}
380+
369381
variable "ami_filter" {
370-
description = "Map of lists used to create the AMI filter for the action runner AMI."
382+
description = "[DEPRECATED: Use ami.filter] Map of lists used to create the AMI filter for the action runner AMI."
371383
type = map(list(string))
372384
default = { state = ["available"] }
373385
validation {
374386
# check the availability of the AMI
375387
condition = contains(keys(var.ami_filter), "state")
376-
error_message = "The \"ami_filter\" variable must contain the \"state\" key with the value \"available\"."
388+
error_message = "The AMI filter must contain the state filter."
377389
}
378390
}
379391

380392
variable "ami_owners" {
381-
description = "The list of owners used to select the AMI of action runner instances."
393+
description = "[DEPRECATED: Use ami.owners] The list of owners that should be used to find the AMI."
382394
type = list(string)
383395
default = ["amazon"]
384396
}
385397

386-
variable "ami_id_ssm_parameter_arn" {
387-
description = "ARN of the SSM parameter (of data type aws:ec2:image) that contains the AMI ID to launch runner instances from. Overrides ami_filter"
398+
variable "ami_id_ssm_parameter_name" {
399+
description = "[DEPRECATED: Use ami.id_ssm_parameter_name] String used to construct the SSM parameter name used to resolve the latest AMI ID for the runner instances. The SSM parameter should be of type String and contain a valid AMI ID. The default behavior is to use the latest Ubuntu 22.04 AMI."
388400
type = string
389401
default = null
390402
}
391403

392-
variable "ami_id_ssm_parameter_name" {
393-
description = "(DEPRECATED) Variable is replaced by `ami_id_ssm_parameter_arn` Externally managed SSM parameter (of data type aws:ec2:image) that contains the AMI ID to launch runner instances from. Overrides ami_filter"
404+
variable "ami_id_ssm_parameter_arn" {
405+
description = "[DEPRECATED: Use ami.id_ssm_parameter_arn] Arn of the SSM parameter used to resolve the AMI ID for the runner instances. The SSM parameter should be of type String and contain a valid AMI ID."
394406
type = string
395407
default = null
396408
}
397409

398410
variable "ami_kms_key_arn" {
399-
description = "Optional CMK Key ARN to be used to launch an instance from a shared encrypted AMI"
411+
description = "[DEPRECATED: Use ami.kms_key_arn] Optional CMK Key ARN to be used to launch an instance from a shared encrypted AMI"
400412
type = string
401413
default = null
402414
}

0 commit comments

Comments
 (0)