From c34723d47fcd90096b0f5cb446c23a25d4226e9b Mon Sep 17 00:00:00 2001 From: jgutierrez Date: Thu, 21 Sep 2023 12:31:49 +0200 Subject: [PATCH] feat: Adding runner_enable_default_labels variable --- .terraform.lock.hcl | 20 ++++++++++++++++++++ README.md | 3 ++- main.tf | 3 ++- modules/runners/variables.tf | 5 +++++ variables.tf | 13 ++++++++++++- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index b4043fb5eb..f5ff760f92 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -24,6 +24,26 @@ provider "registry.terraform.io/hashicorp/aws" { ] } +provider "registry.terraform.io/hashicorp/null" { + version = "3.2.2" + constraints = "~> 3.2" + hashes = [ + "h1:IMVAUHKoydFrlPrl9OzasDnw/8ntZFerCC9iXw1rXQY=", + "zh:3248aae6a2198f3ec8394218d05bd5e42be59f43a3a7c0b71c66ec0df08b69e7", + "zh:32b1aaa1c3013d33c245493f4a65465eab9436b454d250102729321a44c8ab9a", + "zh:38eff7e470acb48f66380a73a5c7cdd76cc9b9c9ba9a7249c7991488abe22fe3", + "zh:4c2f1faee67af104f5f9e711c4574ff4d298afaa8a420680b0cb55d7bbc65606", + "zh:544b33b757c0b954dbb87db83a5ad921edd61f02f1dc86c6186a5ea86465b546", + "zh:696cf785090e1e8cf1587499516b0494f47413b43cb99877ad97f5d0de3dc539", + "zh:6e301f34757b5d265ae44467d95306d61bef5e41930be1365f5a8dcf80f59452", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:913a929070c819e59e94bb37a2a253c228f83921136ff4a7aa1a178c7cce5422", + "zh:aa9015926cd152425dbf86d1abdbc74bfe0e1ba3d26b3db35051d7b9ca9f72ae", + "zh:bb04798b016e1e1d49bcc76d62c53b56c88c63d6f2dfe38821afef17c416a0e1", + "zh:c23084e1b23577de22603cff752e59128d83cfecc2e6819edadd8cf7a10af11e", + ] +} + provider "registry.terraform.io/hashicorp/random" { version = "3.6.0" constraints = "~> 3.0" diff --git a/README.md b/README.md index f2aa9ecf6f..73de1ea064 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,8 @@ Talk to the forestkeepers in the `runners-channel` on Slack. | [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 | | [runner\_ec2\_tags](#input\_runner\_ec2\_tags) | Map of tags that will be added to the launch template instance tag specifications. | `map(string)` | `{}` | no | | [runner\_egress\_rules](#input\_runner\_egress\_rules) | List of egress rules for the GitHub runner instances. |
list(object({
cidr_blocks = list(string)
ipv6_cidr_blocks = list(string)
prefix_list_ids = list(string)
from_port = number
protocol = string
security_groups = list(string)
self = bool
to_port = number
description = string
}))
|
[
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": null,
"from_port": 0,
"ipv6_cidr_blocks": [
"::/0"
],
"prefix_list_ids": null,
"protocol": "-1",
"security_groups": null,
"self": null,
"to_port": 0
}
]
| no | -| [runner\_extra\_labels](#input\_runner\_extra\_labels) | Extra (custom) labels for the runners (GitHub). Labels checks on the webhook can be enforced by setting `enable_runner_workflow_job_labels_check_all`. GitHub read-only labels should not be provided. | `list(string)` | `[]` | no | +| [runner\_enable\_default\_labels](#input\_runner\_enable\_default\_labels) | Enable default labels for the runners (os, architecture and `self-hosted`). If disabled, the runner will only have the extra labels provided in `runner_extra_labels`. | `bool` | `true` | no | +| [runner\_extra\_labels](#input\_runner\_extra\_labels) | Extra (custom) labels for the runners (GitHub). Separate each label by a comma. Labels checks on the webhook can be enforced by setting `enable_workflow_job_labels_check`. GitHub read-only labels should not be provided. | `list(string)` | `[]` | no | | [runner\_group\_name](#input\_runner\_group\_name) | Name of the runner group. | `string` | `"Default"` | no | | [runner\_iam\_role\_managed\_policy\_arns](#input\_runner\_iam\_role\_managed\_policy\_arns) | Attach AWS or customer-managed IAM policies (by ARN) to the runner IAM role | `list(string)` | `[]` | no | | [runner\_log\_files](#input\_runner\_log\_files) | (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. |
list(object({
log_group_name = string
prefix_log_group = bool
file_path = string
log_stream_name = string
}))
| `null` | no | diff --git a/main.tf b/main.tf index ae0b83eb55..290a15fb6a 100644 --- a/main.tf +++ b/main.tf @@ -8,7 +8,8 @@ locals { key_base64 = module.ssm.parameters.github_app_key_base64 } - runner_labels = sort(distinct(concat(["self-hosted", var.runner_os, var.runner_architecture], var.runner_extra_labels))) + default_runner_labels = distinct(concat(["self-hosted", var.runner_os, var.runner_architecture])) + runner_labels = var.runner_enable_default_labels ? concat(local.default_runner_labels, var.runner_extra_labels) : var.runner_extra_labels ssm_root_path = var.ssm_paths.use_prefix ? "/${var.ssm_paths.root}/${var.prefix}" : "/${var.ssm_paths.root}" } diff --git a/modules/runners/variables.tf b/modules/runners/variables.tf index 038fdbcf6a..586445280d 100644 --- a/modules/runners/variables.tf +++ b/modules/runners/variables.tf @@ -213,6 +213,11 @@ variable "runner_boot_time_in_minutes" { variable "runner_labels" { description = "All the labels for the runners (GitHub) including the default one's(e.g: self-hosted, linux, x64, label1, label2). Separate each label by a comma" type = list(string) + + validation { + condition = var.runner_labels != null && var.runner_labels != [] + error_message = "The runner_labels variable must be set." + } } variable "runner_group_name" { diff --git a/variables.tf b/variables.tf index 99823aae12..24d0b17adf 100644 --- a/variables.tf +++ b/variables.tf @@ -58,10 +58,21 @@ variable "runner_boot_time_in_minutes" { default = 5 } +variable "runner_enable_default_labels" { + description = "Enable default labels for the runners (os, architecture and `self-hosted`). If disabled, the runner will only have the extra labels provided in `runner_extra_labels`." + type = bool + default = true +} + variable "runner_extra_labels" { - description = "Extra (custom) labels for the runners (GitHub). Labels checks on the webhook can be enforced by setting `enable_runner_workflow_job_labels_check_all`. GitHub read-only labels should not be provided." + description = "Extra (custom) labels for the runners (GitHub). Separate each label by a comma. Labels checks on the webhook can be enforced by setting `enable_workflow_job_labels_check`. GitHub read-only labels should not be provided." type = list(string) default = [] + + validation { + condition = var.runner_extra_labels != null + error_message = "Extra labels should not be null." + } } variable "runner_group_name" {