Add meta tags to service template

This commit is contained in:
IamTheFij 2023-01-11 15:40:42 -08:00
parent 19031834fb
commit 0a798aa5a7
3 changed files with 34 additions and 4 deletions

View File

@ -1,9 +1,11 @@
resource "nomad_job" "service" { resource "nomad_job" "service" {
jobspec = templatefile("${path.module}/service_template.nomad", { jobspec = templatefile("${path.module}/service_template.nomad", {
name = var.name name = var.name
image = var.image image = var.image
args = var.args args = var.args
env = var.env env = var.env
meta = var.meta
group_meta = var.group_meta
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 ~}
} }
%{ if length(group_meta) > 0 ~}
meta = {
%{ for k, v in group_meta ~}
${k} = ${jsonencode(v)}
%{ endfor ~}
}
%{ endif ~}
%{ if sticky_disk ~} %{ if sticky_disk ~}
ephemeral_disk { ephemeral_disk {
migrate = true migrate = true
@ -113,6 +121,14 @@ job "${name}" {
task "${name}" { task "${name}" {
driver = "docker" driver = "docker"
%{ if length(meta) > 0 ~}
meta = {
%{ for k, v in meta ~}
${k} = ${jsonencode(v)}
%{ endfor ~}
}
%{ endif ~}
config { config {
image = "${image}" image = "${image}"
%{ if service_port != null ~} %{ if service_port != null ~}

View File

@ -8,6 +8,18 @@ variable "image" {
description = "Image that should be run" description = "Image that should be run"
} }
variable "meta" {
type = map(string)
default = {}
description = "Meta attributes to attach to the task"
}
variable "group_meta" {
type = map(string)
default = {}
description = "Meta attributes to attach to the group"
}
variable "service_port" { variable "service_port" {
type = number type = number
default = null default = null