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

Commit 150d227

Browse files
authored
fix: instance_types from a Set to a List, so instance order preference is preserved (#1154)
* Preserve ordering of chosen instance types * Switch from for_each to count due to for_each not supporting lists for iterating * Missed a each.value * Format launch template list in the order we specify * typo * Missed a change from set to list * Remove unneeded change
1 parent c8b8139 commit 150d227

File tree

5 files changed

+12
-50
lines changed

5 files changed

+12
-50
lines changed

Diff for: README.md

+3-18
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,6 @@ No requirements.
343343
| aws | n/a |
344344
| random | n/a |
345345

346-
## Modules
347-
348-
| Name | Source | Version |
349-
|------|--------|---------|
350-
| runner_binaries | ./modules/runner-binaries-syncer | |
351-
| runners | ./modules/runners | |
352-
| ssm | ./modules/ssm | |
353-
| webhook | ./modules/webhook | |
354-
355-
## Resources
356-
357-
| Name |
358-
|------|
359-
| [aws_resourcegroups_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/resourcegroups_group) |
360-
| [aws_sqs_queue](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue) |
361-
| [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) |
362-
363346
## Inputs
364347

365348
| Name | Description | Type | Default | Required |
@@ -380,7 +363,7 @@ No requirements.
380363
| 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. | <pre>list(object({<br> cron = string<br> timeZone = string<br> idleCount = number<br> }))</pre> | `[]` | no |
381364
| instance\_profile\_path | The path that will be added to the instance\_profile, if not set the environment name will be used. | `string` | `null` | no |
382365
| instance\_type | [DEPRECATED] See instance\_types. | `string` | `"m5.large"` | no |
383-
| instance\_types | List of instance types for the action runner. | `set(string)` | `null` | no |
366+
| instance\_types | List of instance types for the action runner. | `list(string)` | `null` | no |
384367
| key\_name | Key pair name | `string` | `null` | no |
385368
| kms\_key\_arn | Optional CMK Key ARN to be used for Parameter Store. This key must be in the current account. | `string` | `null` | no |
386369
| lambda\_s3\_bucket | S3 bucket from which to specify lambda functions. This is an alternative to providing local files directly. | `any` | `null` | no |
@@ -398,6 +381,7 @@ No requirements.
398381
| runner\_binaries\_syncer\_lambda\_timeout | Time out of the binaries sync lambda in seconds. | `number` | `300` | no |
399382
| runner\_binaries\_syncer\_lambda\_zip | File location of the binaries sync lambda zip file. | `string` | `null` | no |
400383
| runner\_boot\_time\_in\_minutes | The minimum time for an EC2 runner to boot and register as a runner. | `number` | `5` | no |
384+
| runner\_egress\_rules | List of egress rules for the GitHub runner instances. | <pre>list(object({<br> cidr_blocks = list(string)<br> ipv6_cidr_blocks = list(string)<br> prefix_list_ids = list(string)<br> from_port = number<br> protocol = string<br> security_groups = list(string)<br> self = bool<br> to_port = number<br> description = string<br> }))</pre> | <pre>[<br> {<br> "cidr_blocks": [<br> "0.0.0.0/0"<br> ],<br> "description": null,<br> "from_port": 0,<br> "ipv6_cidr_blocks": [<br> "::/0"<br> ],<br> "prefix_list_ids": null,<br> "protocol": "-1",<br> "security_groups": null,<br> "self": null,<br> "to_port": 0<br> }<br>]</pre> | no |
401385
| runner\_extra\_labels | Extra labels for the runners (GitHub). Separate each label by a comma | `string` | `""` | no |
402386
| runner\_group\_name | Name of the runner group. | `string` | `"Default"` | no |
403387
| runner\_iam\_role\_managed\_policy\_arns | Attach AWS or customer-managed IAM policies (by ARN) to the runner IAM role | `list(string)` | `[]` | no |
@@ -431,6 +415,7 @@ No requirements.
431415
| runners | n/a |
432416
| ssm\_parameters | n/a |
433417
| webhook | n/a |
418+
434419
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
435420

436421
## Contribution

Diff for: modules/runners/README.md

+3-26
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,6 @@ No requirements.
5858
|------|---------|
5959
| aws | n/a |
6060

61-
## Modules
62-
63-
No Modules.
64-
65-
## Resources
66-
67-
| Name |
68-
|------|
69-
| [aws_ami](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) |
70-
| [aws_caller_identity](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) |
71-
| [aws_cloudwatch_event_rule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) |
72-
| [aws_cloudwatch_event_target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) |
73-
| [aws_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) |
74-
| [aws_iam_instance_profile](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) |
75-
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) |
76-
| [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) |
77-
| [aws_iam_role_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) |
78-
| [aws_iam_role_policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) |
79-
| [aws_lambda_event_source_mapping](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping) |
80-
| [aws_lambda_function](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) |
81-
| [aws_lambda_permission](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) |
82-
| [aws_launch_template](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) |
83-
| [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) |
84-
| [aws_ssm_parameter](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) |
85-
8661
## Inputs
8762

8863
| Name | Description | Type | Default | Required |
@@ -93,6 +68,7 @@ No Modules.
9368
| block\_device\_mappings | The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops` | `map(string)` | `{}` | no |
9469
| cloudwatch\_config | (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. | `string` | `null` | no |
9570
| create\_service\_linked\_role\_spot | (optional) create the service linked role for spot instances that is required by the scale-up lambda. | `bool` | `false` | no |
71+
| egress\_rules | List of egress rules for the GitHub runner instances. | <pre>list(object({<br> cidr_blocks = list(string)<br> ipv6_cidr_blocks = list(string)<br> prefix_list_ids = list(string)<br> from_port = number<br> protocol = string<br> security_groups = list(string)<br> self = bool<br> to_port = number<br> description = string<br> }))</pre> | <pre>[<br> {<br> "cidr_blocks": [<br> "0.0.0.0/0"<br> ],<br> "description": null,<br> "from_port": 0,<br> "ipv6_cidr_blocks": [<br> "::/0"<br> ],<br> "prefix_list_ids": null,<br> "protocol": "-1",<br> "security_groups": null,<br> "self": null,<br> "to_port": 0<br> }<br>]</pre> | no |
9672
| enable\_cloudwatch\_agent | Enabling the cloudwatch agent on the ec2 runner instances, the runner contains default config. Configuration can be overridden via `cloudwatch_config`. | `bool` | `true` | no |
9773
| enable\_organization\_runners | n/a | `bool` | n/a | yes |
9874
| enable\_ssm\_on\_runners | Enable to allow access to the runner instances for debugging purposes via SSM. Note that this adds additional permissions to the runner instances. | `bool` | n/a | yes |
@@ -102,7 +78,7 @@ No Modules.
10278
| 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. | <pre>list(object({<br> cron = string<br> timeZone = string<br> idleCount = number<br> }))</pre> | `[]` | no |
10379
| instance\_profile\_path | The path that will be added to the instance\_profile, if not set the environment name will be used. | `string` | `null` | no |
10480
| instance\_type | [DEPRECATED] See instance\_types. | `string` | `"m5.large"` | no |
105-
| instance\_types | List of instance types for the action runner. | `set(string)` | `null` | no |
81+
| instance\_types | List of instance types for the action runner. | `list(string)` | `null` | no |
10682
| key\_name | Key pair name | `string` | `null` | no |
10783
| kms\_key\_arn | Optional CMK Key ARN to be used for Parameter Store. | `string` | `null` | no |
10884
| lambda\_s3\_bucket | S3 bucket from which to specify lambda functions. This is an alternative to providing local files directly. | `any` | `null` | no |
@@ -150,6 +126,7 @@ No Modules.
150126
| role\_runner | n/a |
151127
| role\_scale\_down | n/a |
152128
| role\_scale\_up | n/a |
129+
153130
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
154131

155132
## Philips Forest

Diff for: modules/runners/main.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ locals {
1818
userdata_arm_patch = "${path.module}/templates/arm-runner-patch.tpl"
1919
userdata_install_config_runner = "${path.module}/templates/install-config-runner.sh"
2020

21-
instance_types = var.instance_types == null ? [var.instance_type] : var.instance_types
21+
instance_types = distinct(var.instance_types == null ? [var.instance_type] : var.instance_types)
2222

2323
kms_key_arn = var.kms_key_arn != null ? var.kms_key_arn : ""
2424
}
@@ -38,9 +38,9 @@ data "aws_ami" "runner" {
3838
}
3939

4040
resource "aws_launch_template" "runner" {
41-
for_each = local.instance_types
41+
count = length(local.instance_types)
4242

43-
name = "${var.environment}-action-runner-${each.value}"
43+
name = "${var.environment}-action-runner-${local.instance_types[count.index]}"
4444

4545
dynamic "block_device_mappings" {
4646
for_each = [var.block_device_mappings]
@@ -72,7 +72,7 @@ resource "aws_launch_template" "runner" {
7272
}
7373

7474
image_id = data.aws_ami.runner.id
75-
instance_type = each.value
75+
instance_type = local.instance_types[count.index]
7676
key_name = var.key_name
7777

7878
vpc_security_group_ids = compact(concat(

Diff for: modules/runners/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ variable "instance_type" {
6565

6666
variable "instance_types" {
6767
description = "List of instance types for the action runner."
68-
type = set(string)
68+
type = list(string)
6969
default = null
7070
}
7171

Diff for: variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ variable "volume_size" {
351351

352352
variable "instance_types" {
353353
description = "List of instance types for the action runner."
354-
type = set(string)
354+
type = list(string)
355355
default = null
356356
}
357357

0 commit comments

Comments
 (0)