Add constraints and docker devices to service template

This commit is contained in:
IamTheFij 2023-04-20 16:47:07 -07:00
parent bbc8ba5c6b
commit f75d149f32
3 changed files with 38 additions and 0 deletions

View File

@ -7,6 +7,8 @@ resource "nomad_job" "service" {
env = var.env env = var.env
meta = var.meta meta = var.meta
group_meta = var.group_meta group_meta = var.group_meta
constraints = var.constraints
docker_devices = var.docker_devices
service_port = var.service_port service_port = var.service_port
sticky_disk = var.sticky_disk sticky_disk = var.sticky_disk

View File

@ -17,6 +17,14 @@ job "${name}" {
%{ endif } %{ endif }
} }
%{ for constraint in constraints ~}
constraint {
attribute = "${constraint.attribute}"
operator = "${constraint.operator}"
value = "${constraint.value}"
}
%{ endfor ~}
%{ if length(group_meta) > 0 } %{ if length(group_meta) > 0 }
meta = { meta = {
%{ for k, v in group_meta } %{ for k, v in group_meta }
@ -83,6 +91,16 @@ job "${name}" {
%{ if length(try(args, [])) > 0 ~} %{ if length(try(args, [])) > 0 ~}
args = ${jsonencode(args)} args = ${jsonencode(args)}
%{ endif ~} %{ 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 ~} %{ for template in templates ~}
%{ if template.mount && !template.env ~} %{ if template.mount && !template.env ~}

View File

@ -137,3 +137,21 @@ variable "mysql_bootstrap" {
}) })
default = null 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 = []
}