From 2e2e4f206419bd8c88cc7c3406aef11b96fae1ca Mon Sep 17 00:00:00 2001 From: IamTheFij Date: Mon, 21 Aug 2023 22:30:18 -0700 Subject: [PATCH] Add ability to set meta at job level --- services/service/main.tf | 3 ++- services/service/service_template.nomad | 12 ++++++++++-- services/service/vars.tf | 8 +++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/services/service/main.tf b/services/service/main.tf index 6070060..efdf686 100644 --- a/services/service/main.tf +++ b/services/service/main.tf @@ -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 diff --git a/services/service/service_template.nomad b/services/service/service_template.nomad index 49fe50d..b1c3323 100644 --- a/services/service/service_template.nomad +++ b/services/service/service_template.nomad @@ -5,6 +5,14 @@ job "${name}" { type = "service" priority = ${priority} + %{ if length(job_meta) > 0 } + meta = { + %{ for k, v in job_meta } + ${k} = ${jsonencode(v)} + %{ endfor } + } + %{~ endif } + group "${name}" { count = ${count} @@ -98,9 +106,9 @@ job "${name}" { 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 ~} } diff --git a/services/service/vars.tf b/services/service/vars.tf index 43b1090..f35b44e 100644 --- a/services/service/vars.tf +++ b/services/service/vars.tf @@ -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 job" +} + variable "service_port" { type = number default = null