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

Commit e2cf7ac

Browse files
feat(runners): allow explicitly standard or unlimited (#3244)
* feat: Add var.runner_credit_specification Allow configuring T instance types as explicitly standard or unlimited credit model. This can help to control costs when using T instances as a "cpu-limited" runner pool. * docs: auto update terraform docs * Correct validation logic * Improve description * docs: auto update terraform docs * Add credit_specification to multi-runner too * Allow per-runner credit specification Also use it in the multi-runner example, as a test. * docs: auto update terraform docs --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1e0fbfc commit e2cf7ac

File tree

11 files changed

+40
-2
lines changed

11 files changed

+40
-2
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ We welcome any improvement to the standard module to make the default as secure
560560
| <a name="input_runner_binaries_syncer_lambda_timeout"></a> [runner\_binaries\_syncer\_lambda\_timeout](#input\_runner\_binaries\_syncer\_lambda\_timeout) | Time out of the binaries sync lambda in seconds. | `number` | `300` | no |
561561
| <a name="input_runner_binaries_syncer_lambda_zip"></a> [runner\_binaries\_syncer\_lambda\_zip](#input\_runner\_binaries\_syncer\_lambda\_zip) | File location of the binaries sync lambda zip file. | `string` | `null` | no |
562562
| <a name="input_runner_boot_time_in_minutes"></a> [runner\_boot\_time\_in\_minutes](#input\_runner\_boot\_time\_in\_minutes) | The minimum time for an EC2 runner to boot and register as a runner. | `number` | `5` | no |
563+
| <a name="input_runner_credit_specification"></a> [runner\_credit\_specification](#input\_runner\_credit\_specification) | The credit option for CPU usage of a T instance. Can be unset, "standard" or "unlimited". | `string` | `null` | no |
563564
| <a name="input_runner_ec2_tags"></a> [runner\_ec2\_tags](#input\_runner\_ec2\_tags) | Map of tags that will be added to the launch template instance tag specifications. | `map(string)` | `{}` | no |
564565
| <a name="input_runner_egress_rules"></a> [runner\_egress\_rules](#input\_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 |
565566
| <a name="input_runner_enable_workflow_job_labels_check_all"></a> [runner\_enable\_workflow\_job\_labels\_check\_all](#input\_runner\_enable\_workflow\_job\_labels\_check\_all) | DEPCRECATED: Replaced by `enable_runner_workflow_job_labels_check_all`. | `string` | `null` | no |

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

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ runner_config:
1313
runner_extra_labels: amazon
1414
runner_name_prefix: amazon-arm64_
1515
enable_ssm_on_runners: true
16+
credit_specification: unlimited
1617
instance_types:
1718
- t4g.large
1819
- c6g.large

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ runner_config:
1515
runner_run_as: ubuntu
1616
runner_name_prefix: ubuntu-2204-x64_
1717
enable_ssm_on_runners: true
18+
credit_specification: standard
1819
instance_types:
20+
- t3a.large
1921
- m5ad.large
2022
- m5a.large
2123
runners_maximum_count: 1
@@ -48,4 +50,4 @@ runner_config:
4850
- log_group_name: runner
4951
prefix_log_group: true
5052
file_path: /opt/actions-runner/_diag/Runner_**.log
51-
log_stream_name: "{instance_id}/runner"
53+
log_stream_name: "{instance_id}/runner"

Diff for: main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ module "runners" {
224224
egress_rules = var.runner_egress_rules
225225
runner_additional_security_group_ids = var.runner_additional_security_group_ids
226226
metadata_options = var.runner_metadata_options
227+
credit_specification = var.runner_credit_specification
227228

228229
enable_runner_binaries_syncer = var.enable_runner_binaries_syncer
229230
lambda_s3_bucket = var.lambda_s3_bucket

Diff for: modules/multi-runner/README.md

+1-1
Large diffs are not rendered by default.

Diff for: modules/multi-runner/runners.tf

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module "runners" {
5151
egress_rules = var.runner_egress_rules
5252
runner_additional_security_group_ids = var.runner_additional_security_group_ids
5353
metadata_options = each.value.runner_config.runner_metadata_options
54+
credit_specification = each.value.runner_config.credit_specification
5455

5556
enable_runner_binaries_syncer = each.value.runner_config.enable_runner_binaries_syncer
5657
lambda_s3_bucket = var.lambda_s3_bucket

Diff for: modules/multi-runner/variables.tf

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ variable "multi_runner_config" {
4141
ami_id_ssm_parameter_name = optional(string, null)
4242
ami_kms_key_arn = optional(string, "")
4343
create_service_linked_role_spot = optional(bool, false)
44+
credit_specification = optional(string, null)
4445
delay_webhook_event = optional(number, 30)
4546
disable_runner_autoupdate = optional(bool, false)
4647
enable_ephemeral_runners = optional(bool, false)
@@ -132,6 +133,7 @@ variable "multi_runner_config" {
132133
ami_filter: "(Optional) List of maps used to create the AMI filter for the action runner AMI. By default amazon linux 2 is used."
133134
ami_owners: "(Optional) The list of owners used to select the AMI of action runner instances."
134135
create_service_linked_role_spot: (Optional) create the serviced linked role for spot instances that is required by the scale-up lambda.
136+
credit_specification: "(Optional) The credit specification of the runner instance_type. Can be unset, `standard` or `unlimited`.
135137
delay_webhook_event: "The number of seconds the event accepted by the webhook is invisible on the queue before the scale up lambda will receive the event."
136138
disable_runner_autoupdate: "Disable the auto update of the github runner agent. Be-aware there is a grace period of 30 days, see also the [GitHub article](https://github.blog/changelog/2022-02-01-github-actions-self-hosted-runners-can-now-disable-automatic-updates/)"
137139
enable_ephemeral_runners: "Enable ephemeral runners, runners will only be used once."

Diff for: modules/runners/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ yarn run dist
132132
| <a name="input_block_device_mappings"></a> [block\_device\_mappings](#input\_block\_device\_mappings) | The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops`, `throughput`, `kms_key_id`, `snapshot_id`. | <pre>list(object({<br> delete_on_termination = optional(bool, true)<br> device_name = optional(string, "/dev/xvda")<br> encrypted = optional(bool, true)<br> iops = optional(number)<br> kms_key_id = optional(string)<br> snapshot_id = optional(string)<br> throughput = optional(number)<br> volume_size = number<br> volume_type = optional(string, "gp3")<br> }))</pre> | <pre>[<br> {<br> "volume_size": 30<br> }<br>]</pre> | no |
133133
| <a name="input_cloudwatch_config"></a> [cloudwatch\_config](#input\_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 |
134134
| <a name="input_create_service_linked_role_spot"></a> [create\_service\_linked\_role\_spot](#input\_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 |
135+
| <a name="input_credit_specification"></a> [credit\_specification](#input\_credit\_specification) | The credit option for CPU usage of a T instance. Can be unset, "standard" or "unlimited". | `string` | `null` | no |
135136
| <a name="input_disable_runner_autoupdate"></a> [disable\_runner\_autoupdate](#input\_disable\_runner\_autoupdate) | Disable the auto update of the github runner agent. Be-aware there is a grace period of 30 days, see also the [GitHub article](https://github.blog/changelog/2022-02-01-github-actions-self-hosted-runners-can-now-disable-automatic-updates/) | `bool` | `false` | no |
136137
| <a name="input_egress_rules"></a> [egress\_rules](#input\_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 |
137138
| <a name="input_enable_cloudwatch_agent"></a> [enable\_cloudwatch\_agent](#input\_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 |

Diff for: modules/runners/main.tf

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ resource "aws_launch_template" "runner" {
9797
}
9898
}
9999

100+
dynamic "credit_specification" {
101+
for_each = var.credit_specification != null ? [var.credit_specification] : []
102+
content {
103+
cpu_credits = credit_specification.value
104+
}
105+
}
106+
100107
monitoring {
101108
enabled = var.enable_runner_detailed_monitoring
102109
}

Diff for: modules/runners/variables.tf

+11
Original file line numberDiff line numberDiff line change
@@ -594,3 +594,14 @@ variable "lambda_tracing_mode" {
594594
type = string
595595
default = null
596596
}
597+
598+
variable "credit_specification" {
599+
description = "The credit option for CPU usage of a T instance. Can be unset, \"standard\" or \"unlimited\"."
600+
type = string
601+
default = null
602+
603+
validation {
604+
condition = var.credit_specification == null ? true : contains(["standard", "unlimited"], var.credit_specification)
605+
error_message = "Valid values for credit_specification are (null, \"standard\", \"unlimited\")."
606+
}
607+
}

Diff for: variables.tf

+11
Original file line numberDiff line numberDiff line change
@@ -777,3 +777,14 @@ variable "lambda_tracing_mode" {
777777
type = string
778778
default = null
779779
}
780+
781+
variable "runner_credit_specification" {
782+
description = "The credit option for CPU usage of a T instance. Can be unset, \"standard\" or \"unlimited\"."
783+
type = string
784+
default = null
785+
786+
validation {
787+
condition = var.runner_credit_specification == null ? true : contains(["standard", "unlimited"], var.runner_credit_specification)
788+
error_message = "Valid values for runner_credit_specification are (null, \"standard\", \"unlimited\")."
789+
}
790+
}

0 commit comments

Comments
 (0)