From c50d8b8bf28721d1c7869fcc182382d764c354b2 Mon Sep 17 00:00:00 2001 From: Peter Mikus Date: Tue, 23 Sep 2025 08:26:05 +0200 Subject: [PATCH] feat(terraform): Improved dispatcher Signed-off-by: Peter Mikus Change-Id: Ic9804865fba42d1a455407e15c03b48121795d7d --- .../terraform-nomad-gha-dispatcher/README.md | 42 ++++++++++++++++++++ .../terraform-nomad-gha-dispatcher/main.tf | 13 ++++--- .../nomad-gha-dispatcher-sandbox.hcl.tftpl | 45 ---------------------- ...od.hcl.tftpl => nomad-gha-dispatcher.hcl.tftpl} | 11 ++++++ .../terraform-nomad-gha-dispatcher/variables.tf | 24 ++++++++---- 5 files changed, 78 insertions(+), 57 deletions(-) create mode 100644 fdio.infra.terraform/terraform-nomad-gha-dispatcher/README.md delete mode 100644 fdio.infra.terraform/terraform-nomad-gha-dispatcher/nomad-gha-dispatcher-sandbox.hcl.tftpl rename fdio.infra.terraform/terraform-nomad-gha-dispatcher/{nomad-gha-dispatcher-prod.hcl.tftpl => nomad-gha-dispatcher.hcl.tftpl} (78%) diff --git a/fdio.infra.terraform/terraform-nomad-gha-dispatcher/README.md b/fdio.infra.terraform/terraform-nomad-gha-dispatcher/README.md new file mode 100644 index 0000000000..914f08af05 --- /dev/null +++ b/fdio.infra.terraform/terraform-nomad-gha-dispatcher/README.md @@ -0,0 +1,42 @@ + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.12.1 | +| [nomad](#requirement\_nomad) | >= 2.5.0 | + +## Providers + +| Name | Version | +|------|---------| +| [nomad](#provider\_nomad) | 2.5.0 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [nomad_job.gha-dispatcher](https://registry.terraform.io/providers/hashicorp/nomad/latest/docs/resources/job) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [cpu](#input\_cpu) | Specifies the CPU required to run this task in MHz. | `number` | `12000` | no | +| [datacenters](#input\_datacenters) | Specifies the list of DCs to be considered placing this task. | `list(string)` |
[
"yul1"
]
| no | +| [dispatchers](#input\_dispatchers) | n/a |
list(object({
namespace = string
repository = string
}))
|
[
{
"namespace": "sandbox",
"repository": "fdio-csit"
},
{
"namespace": "prod",
"repository": "fdio-csit"
}
]
| no | +| [image](#input\_image) | Specifies the Docker image to run. | `string` | `"pmikus/docker-gha-dispatcher"` | no | +| [job\_name](#input\_job\_name) | Specifies a name for the job. | `string` | `"gha-dispatcher"` | no | +| [memory](#input\_memory) | Specifies the memory required in MB. | `number` | `8000` | no | +| [node\_pool](#input\_node\_pool) | Specifies the node pool to place the job in. | `string` | `"default"` | no | +| [region](#input\_region) | The region in which to execute the job. | `string` | `"global"` | no | +| [type](#input\_type) | Specifies the Nomad scheduler to use. | `string` | `"service"` | no | + +## Outputs + +No outputs. + \ No newline at end of file diff --git a/fdio.infra.terraform/terraform-nomad-gha-dispatcher/main.tf b/fdio.infra.terraform/terraform-nomad-gha-dispatcher/main.tf index 635317ac4a..9395bdee79 100644 --- a/fdio.infra.terraform/terraform-nomad-gha-dispatcher/main.tf +++ b/fdio.infra.terraform/terraform-nomad-gha-dispatcher/main.tf @@ -1,18 +1,21 @@ locals { datacenters = join(",", var.datacenters) + flat_dispatchers = { + for dispatcher in var.dispatchers : dispatcher.namespace => dispatcher + } } resource "nomad_job" "gha-dispatcher" { - for_each = toset(var.namespace) + for_each = local.flat_dispatchers jobspec = templatefile( - "${path.cwd}/nomad-${var.job_name}-${each.key}.hcl.tftpl", + "${path.cwd}/nomad-${var.job_name}.hcl.tftpl", { cpu = var.cpu, datacenters = local.datacenters, - image = "${var.image}-${each.key}:latest", - job_name = "${var.job_name}-${each.key}", + image = "${var.image}-${each.value.namespace}:latest", + job_name = "${var.job_name}-${each.value.namespace}-${each.value.repository}", memory = var.memory, - namespace = each.key, + namespace = each.value.namespace, node_pool = var.node_pool, region = var.region, type = var.type diff --git a/fdio.infra.terraform/terraform-nomad-gha-dispatcher/nomad-gha-dispatcher-sandbox.hcl.tftpl b/fdio.infra.terraform/terraform-nomad-gha-dispatcher/nomad-gha-dispatcher-sandbox.hcl.tftpl deleted file mode 100644 index ea17f9c7ce..0000000000 --- a/fdio.infra.terraform/terraform-nomad-gha-dispatcher/nomad-gha-dispatcher-sandbox.hcl.tftpl +++ /dev/null @@ -1,45 +0,0 @@ -job "${job_name}" { - datacenters = ["${datacenters}"] - type = "${type}" - node_pool = "${node_pool}" - region = "${region}" - namespace = "${namespace}" - - group "${job_name}" { - count = 1 - constraint { - attribute = "$${attr.cpu.arch}" - value = "amd64" - } - constraint { - attribute = "$${node.class}" - value = "builder" - } - ephemeral_disk { - migrate = false - size = 3000 - sticky = false - } - task "${job_name}" { - driver = "docker" - config { - image = "${image}" - } - template { - destination = "$${NOMAD_SECRETS_DIR}/.env" - env = true - data = <