--- /dev/null
+<!-- BEGIN_TF_DOCS -->
+## Requirements
+
+| Name | Version |
+|------|---------|
+| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.12.1 |
+| <a name="requirement_nomad"></a> [nomad](#requirement\_nomad) | >= 2.5.0 |
+
+## Providers
+
+| Name | Version |
+|------|---------|
+| <a name="provider_nomad"></a> [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 |
+|------|-------------|------|---------|:--------:|
+| <a name="input_cpu"></a> [cpu](#input\_cpu) | Specifies the CPU required to run this task in MHz. | `number` | `12000` | no |
+| <a name="input_datacenters"></a> [datacenters](#input\_datacenters) | Specifies the list of DCs to be considered placing this task. | `list(string)` | <pre>[<br/> "yul1"<br/>]</pre> | no |
+| <a name="input_dispatchers"></a> [dispatchers](#input\_dispatchers) | n/a | <pre>list(object({<br/> namespace = string<br/> repository = string<br/> }))</pre> | <pre>[<br/> {<br/> "namespace": "sandbox",<br/> "repository": "fdio-csit"<br/> },<br/> {<br/> "namespace": "prod",<br/> "repository": "fdio-csit"<br/> }<br/>]</pre> | no |
+| <a name="input_image"></a> [image](#input\_image) | Specifies the Docker image to run. | `string` | `"pmikus/docker-gha-dispatcher"` | no |
+| <a name="input_job_name"></a> [job\_name](#input\_job\_name) | Specifies a name for the job. | `string` | `"gha-dispatcher"` | no |
+| <a name="input_memory"></a> [memory](#input\_memory) | Specifies the memory required in MB. | `number` | `8000` | no |
+| <a name="input_node_pool"></a> [node\_pool](#input\_node\_pool) | Specifies the node pool to place the job in. | `string` | `"default"` | no |
+| <a name="input_region"></a> [region](#input\_region) | The region in which to execute the job. | `string` | `"global"` | no |
+| <a name="input_type"></a> [type](#input\_type) | Specifies the Nomad scheduler to use. | `string` | `"service"` | no |
+
+## Outputs
+
+No outputs.
+<!-- END_TF_DOCS -->
\ No newline at end of file
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
+++ /dev/null
-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 = <<EOT
-{{- with nomadVar "nomad/jobs" -}}
-{{- range $k, $v := . }}
-{{ $k }}={{ $v }}
-{{- end }}
-{{- end }}
-EOT
- }
- resources {
- cpu = ${cpu}
- memory = ${memory}
- }
- }
- }
-}
\ No newline at end of file
{{ $k }}={{ $v }}
{{- end }}
{{- end }}
+EOT
+ }
+ template {
+ destination = "$${NOMAD_SECRETS_DIR}/.job"
+ env = true
+ data = <<EOT
+{{- with nomadVar "nomad/jobs/${job_name}" -}}
+{{- range $k, $v := . }}
+{{ $k }}={{ $v }}
+{{- end }}
+{{- end }}
EOT
}
resources {
type = number
default = 8000
}
-
-variable "namespace" {
- description = "The namespace in which to execute the job."
- type = set(string)
- default = ["prod","sandbox"]
-}
-
variable "node_pool" {
description = "Specifies the node pool to place the job in."
type = string
description = "Specifies the Nomad scheduler to use."
type = string
default = "service"
+}
+
+variable "dispatchers" {
+ type = list(object({
+ namespace = string
+ repository = string
+ }))
+ default = [
+ {
+ namespace = "sandbox"
+ repository = "fdio-csit"
+ },
+ {
+ namespace = "prod"
+ repository = "fdio-csit"
+ },
+ ]
}
\ No newline at end of file