Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Changed the ami filters to ensure that AMI is available before its used in launch template. #3220

Merged
merged 13 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ We welcome any improvement to the standard module to make the default as secure

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
2 changes: 1 addition & 1 deletion examples/ephemeral/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module "runners" {

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
matcherConfig:
exactMatch: true
labelMatchers:
- [ self-hosted, linux, x64, ubuntu-latest ]
- [ self-hosted, linux, x64, ubuntu-2204 ]
- [self-hosted, linux, x64, ubuntu-latest]
- [self-hosted, linux, x64, ubuntu-2204]
fifo: true
delay_webhook_event: 0
redrive_build_queue:
Expand All @@ -26,6 +26,8 @@ runner_config:
ami_filter:
name:
- ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*
state:
- available
block_device_mappings:
- device_name: /dev/sda1
delete_on_termination: true
Expand All @@ -48,4 +50,4 @@ runner_config:
- log_group_name: runner
prefix_log_group: true
file_path: /opt/actions-runner/_diag/Runner_**.log
log_stream_name: "{instance_id}/runner"
log_stream_name: "{instance_id}/runner"
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ runner_config:
runner_boot_time_in_minutes: 20
ami_filter:
name:
- Windows_Server-2022-English-Core-ContainersLatest-*
- Windows_Server-2022-English-Core-ContainersLatest-*
state:
- available
4 changes: 2 additions & 2 deletions examples/prebuilt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Assuming you have built the `linux-amzn2` image which has a pre-defined AMI name
module "runners" {
...
# set the name of the ami to use
ami_filter = { name = ["github-runner-amzn2-x86_64-2021*"] }
ami_filter = { name = ["github-runner-amzn2-x86_64-2021*"], state = ["available"] }
# provide the owner id of
ami_owners = ["<your owner id>"]

Expand Down Expand Up @@ -139,4 +139,4 @@ Be-aware some shells will print some end of line character `%`.
|------|-------------|
| <a name="output_webhook_endpoint"></a> [webhook\_endpoint](#output\_webhook\_endpoint) | n/a |
| <a name="output_webhook_secret"></a> [webhook\_secret](#output\_webhook\_secret) | n/a |
<!-- END_TF_DOCS -->
<!-- END_TF_DOCS -->
2 changes: 1 addition & 1 deletion examples/prebuilt/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module "runners" {

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

# Look up runner AMI ID from an AWS SSM parameter (overrides ami_filter at instance launch time)
Expand Down
5 changes: 3 additions & 2 deletions examples/ubuntu/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ module "runners" {
ami_owners = ["099720109477"] # Canonical's Amazon account ID

ami_filter = {
name = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
name = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"],
state = ["available"]
}

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

Expand Down
2 changes: 1 addition & 1 deletion modules/runners/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ yarn run dist

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
7 changes: 6 additions & 1 deletion modules/runners/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ variable "instance_types" {
variable "ami_filter" {
description = "Map of lists used to create the AMI filter for the action runner AMI."
type = map(list(string))
default = null
default = { state = ["available"] }
validation {
// check the availability of the AMI
condition = contains(keys(var.ami_filter), "state")
error_message = "The \"ami_filter\" variable must contain the \"state\" key with the value \"available\"."
}
}

variable "ami_owners" {
Expand Down
9 changes: 7 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,14 @@ variable "block_device_mappings" {
}

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

variable "ami_owners" {
Expand Down