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

Commit 0bcfbc7

Browse files
GuptaNavdeep1983github-actions[bot]npalm
authored
fix: Changed the ami filters to ensure that AMI is available before its used in launch template. (#3220)
* fix: Fixed default filters for the AMI. * docs: auto update terraform docs * fix: additional changes. * docs: auto update terraform docs * fix: reverted extra variables. * docs: auto update terraform docs * fix: more changes. * docs: auto update terraform docs * fix: missed. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Niek Palm <[email protected]>
1 parent 116ea58 commit 0bcfbc7

File tree

10 files changed

+28
-13
lines changed

10 files changed

+28
-13
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ We welcome any improvement to the standard module to make the default as secure
486486

487487
| Name | Description | Type | Default | Required |
488488
|------|-------------|------|---------|:--------:|
489-
| <a name="input_ami_filter"></a> [ami\_filter](#input\_ami\_filter) | List of maps used to create the AMI filter for the action runner AMI. By default amazon linux 2 is used. | `map(list(string))` | `null` | no |
489+
| <a name="input_ami_filter"></a> [ami\_filter](#input\_ami\_filter) | Map of lists used to create the AMI filter for the action runner AMI. | `map(list(string))` | <pre>{<br> "state": [<br> "available"<br> ]<br>}</pre> | no |
490490
| <a name="input_ami_id_ssm_parameter_name"></a> [ami\_id\_ssm\_parameter\_name](#input\_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 | `string` | `null` | no |
491491
| <a name="input_ami_kms_key_arn"></a> [ami\_kms\_key\_arn](#input\_ami\_kms\_key\_arn) | Optional CMK Key ARN to be used to launch an instance from a shared encrypted AMI | `string` | `null` | no |
492492
| <a name="input_ami_owners"></a> [ami\_owners](#input\_ami\_owners) | The list of owners used to select the AMI of action runner instances. | `list(string)` | <pre>[<br> "amazon"<br>]</pre> | no |

Diff for: examples/ephemeral/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module "runners" {
7171

7272
# configure your pre-built AMI
7373
# enable_userdata = false
74-
# ami_filter = { name = ["github-runner-amzn2-x86_64-*"] }
74+
# ami_filter = { name = ["github-runner-amzn2-x86_64-*"], state = ["available"] }
7575
# data "aws_caller_identity" "current" {}
7676
# ami_owners = [data.aws_caller_identity.current.account_id]
7777

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
matcherConfig:
22
exactMatch: true
33
labelMatchers:
4-
- [ self-hosted, linux, x64, ubuntu-latest ]
5-
- [ self-hosted, linux, x64, ubuntu-2204 ]
4+
- [self-hosted, linux, x64, ubuntu-latest]
5+
- [self-hosted, linux, x64, ubuntu-2204]
66
fifo: true
77
delay_webhook_event: 0
88
redrive_build_queue:
@@ -28,6 +28,8 @@ runner_config:
2828
ami_filter:
2929
name:
3030
- ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*
31+
state:
32+
- available
3133
block_device_mappings:
3234
- device_name: /dev/sda1
3335
delete_on_termination: true

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ runner_config:
1818
runner_boot_time_in_minutes: 20
1919
ami_filter:
2020
name:
21-
- Windows_Server-2022-English-Core-ContainersLatest-*
21+
- Windows_Server-2022-English-Core-ContainersLatest-*
22+
state:
23+
- available

Diff for: examples/prebuilt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Assuming you have built the `linux-amzn2` image which has a pre-defined AMI name
5858
module "runners" {
5959
...
6060
# set the name of the ami to use
61-
ami_filter = { name = ["github-runner-amzn2-x86_64-2021*"] }
61+
ami_filter = { name = ["github-runner-amzn2-x86_64-2021*"], state = ["available"] }
6262
# provide the owner id of
6363
ami_owners = ["<your owner id>"]
6464

Diff for: examples/prebuilt/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module "runners" {
4242

4343
# configure your pre-built AMI
4444
enable_userdata = false
45-
ami_filter = { name = [var.ami_name_filter] }
45+
ami_filter = { name = [var.ami_name_filter], state = ["available"] }
4646
ami_owners = [data.aws_caller_identity.current.account_id]
4747

4848
# Look up runner AMI ID from an AWS SSM parameter (overrides ami_filter at instance launch time)

Diff for: examples/ubuntu/main.tf

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ module "runners" {
5151
ami_owners = ["099720109477"] # Canonical's Amazon account ID
5252

5353
ami_filter = {
54-
name = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
54+
name = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"],
55+
state = ["available"]
5556
}
5657

5758
# Custom build AMI, no custom userdata needed.
5859
# option 2: Build custom AMI see ../../images/ubuntu-focal
5960
# disable lines above (option 1) and enable the ones below
60-
# ami_filter = { name = ["github-runner-ubuntu-focal-amd64-*"] }
61+
# ami_filter = { name = ["github-runner-ubuntu-focal-amd64-*"], state = ["available"] }
6162
# data "aws_caller_identity" "current" {}
6263
# ami_owners = [data.aws_caller_identity.current.account_id]
6364

Diff for: modules/runners/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ yarn run dist
121121

122122
| Name | Description | Type | Default | Required |
123123
|------|-------------|------|---------|:--------:|
124-
| <a name="input_ami_filter"></a> [ami\_filter](#input\_ami\_filter) | Map of lists used to create the AMI filter for the action runner AMI. | `map(list(string))` | `null` | no |
124+
| <a name="input_ami_filter"></a> [ami\_filter](#input\_ami\_filter) | Map of lists used to create the AMI filter for the action runner AMI. | `map(list(string))` | <pre>{<br> "state": [<br> "available"<br> ]<br>}</pre> | no |
125125
| <a name="input_ami_id_ssm_parameter_name"></a> [ami\_id\_ssm\_parameter\_name](#input\_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 | `string` | `null` | no |
126126
| <a name="input_ami_kms_key_arn"></a> [ami\_kms\_key\_arn](#input\_ami\_kms\_key\_arn) | Optional CMK Key ARN to be used to launch an instance from a shared encrypted AMI | `string` | `null` | no |
127127
| <a name="input_ami_owners"></a> [ami\_owners](#input\_ami\_owners) | The list of owners used to select the AMI of action runner instances. | `list(string)` | <pre>[<br> "amazon"<br>]</pre> | no |

Diff for: modules/runners/variables.tf

+6-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ variable "instance_types" {
127127
variable "ami_filter" {
128128
description = "Map of lists used to create the AMI filter for the action runner AMI."
129129
type = map(list(string))
130-
default = null
130+
default = { state = ["available"] }
131+
validation {
132+
// check the availability of the AMI
133+
condition = contains(keys(var.ami_filter), "state")
134+
error_message = "The \"ami_filter\" variable must contain the \"state\" key with the value \"available\"."
135+
}
131136
}
132137

133138
variable "ami_owners" {

Diff for: variables.tf

+7-2
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,14 @@ variable "block_device_mappings" {
302302
}
303303

304304
variable "ami_filter" {
305-
description = "List of maps used to create the AMI filter for the action runner AMI. By default amazon linux 2 is used."
305+
description = "Map of lists used to create the AMI filter for the action runner AMI."
306306
type = map(list(string))
307-
default = null
307+
default = { state = ["available"] }
308+
validation {
309+
// check the availability of the AMI
310+
condition = contains(keys(var.ami_filter), "state")
311+
error_message = "The \"ami_filter\" variable must contain the \"state\" key with the value \"available\"."
312+
}
308313
}
309314

310315
variable "ami_owners" {

0 commit comments

Comments
 (0)