Add ability to set job meta for services

This commit is contained in:
IamTheFij 2023-08-24 15:41:18 -07:00
parent 7aa5b800ba
commit 2efc7f8c2f
3 changed files with 18 additions and 4 deletions

View File

@ -7,8 +7,9 @@ resource "nomad_job" "service" {
image_pull_timeout = var.image_pull_timeout
args = var.args
env = var.env
meta = var.meta
task_meta = var.task_meta
group_meta = var.group_meta
job_meta = var.job_meta
constraints = var.constraints
docker_devices = var.docker_devices

View File

@ -7,6 +7,13 @@ job "${name}" {
group "${name}" {
count = ${count}
%{~ if length(job_meta) > 0 }
meta = {
%{ for k, v in job_meta ~}
${k} = ${jsonencode(v)}
%{ endfor ~}
}
%{~ endif ~}
network {
mode = "bridge"
@ -97,9 +104,9 @@ job "${name}" {
%{~ endfor ~}
task "${name}" {
driver = "docker"
%{~ if length(meta) > 0 }
%{~ if length(task_meta) > 0 }
meta = {
%{ for k, v in meta ~}
%{ for k, v in task_meta ~}
${k} = ${jsonencode(v)}
%{ endfor ~}
}

View File

@ -27,7 +27,7 @@ variable "image_pull_timeout" {
description = "A time duration that controls how long Nomad will wait before cancelling an in-progress pull of the Docker image"
}
variable "meta" {
variable "task_meta" {
type = map(string)
default = {}
description = "Meta attributes to attach to the task"
@ -39,6 +39,12 @@ variable "group_meta" {
description = "Meta attributes to attach to the group"
}
variable "job_meta" {
type = map(string)
default = {}
description = "Meta attributes to attach to the task"
}
variable "service_port" {
type = number
default = null