From f75d149f325510043bbb4cca5c7d1b25393c2d4d Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 20 Apr 2023 16:47:07 -0700 Subject: [PATCH] Add constraints and docker devices to service template --- services/service/main.tf | 2 ++ services/service/service_template.nomad | 18 ++++++++++++++++++ services/service/vars.tf | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/services/service/main.tf b/services/service/main.tf index b0e512b..7e52fb2 100644 --- a/services/service/main.tf +++ b/services/service/main.tf @@ -7,6 +7,8 @@ resource "nomad_job" "service" { env = var.env meta = var.meta group_meta = var.group_meta + constraints = var.constraints + docker_devices = var.docker_devices service_port = var.service_port sticky_disk = var.sticky_disk diff --git a/services/service/service_template.nomad b/services/service/service_template.nomad index 2244d61..5092f17 100644 --- a/services/service/service_template.nomad +++ b/services/service/service_template.nomad @@ -17,6 +17,14 @@ job "${name}" { %{ endif } } + %{ for constraint in constraints ~} + constraint { + attribute = "${constraint.attribute}" + operator = "${constraint.operator}" + value = "${constraint.value}" + } + + %{ endfor ~} %{ if length(group_meta) > 0 } meta = { %{ for k, v in group_meta } @@ -83,6 +91,16 @@ job "${name}" { %{ if length(try(args, [])) > 0 ~} args = ${jsonencode(args)} %{ endif ~} + %{ if length(docker_devices) > 0 ~} + devices = [ + %{ for dev in docker_devices } + { + host_path = "${dev.host_path}" + container_path = "${dev.container_path}" + }, + %{ endfor } + ] + %{ endif ~} %{ for template in templates ~} %{ if template.mount && !template.env ~} diff --git a/services/service/vars.tf b/services/service/vars.tf index 988b7e5..2632a08 100644 --- a/services/service/vars.tf +++ b/services/service/vars.tf @@ -137,3 +137,21 @@ variable "mysql_bootstrap" { }) default = null } + +variable "constraints" { + type = list(object({ + attribute = optional(string, "") + operator = optional(string, "=") + value = optional(string, "") + })) + default = [] +} + +variable "docker_devices" { + type = list(object({ + host_path = string + container_path = string + })) + + default = [] +}