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" {
jobspec = templatefile("${path.module}/service_template.nomad", {
name = var.name
image = var.image
args = var.args
env = var.env
name = var.name
image = var.image
args = var.args
env = var.env
meta = var.meta
group_meta = var.group_meta
service_port = var.service_port
sticky_disk = var.sticky_disk

View File

@ -17,6 +17,14 @@ job "${name}" {
%{ endif ~}
}
%{ if length(group_meta) > 0 ~}
meta = {
%{ for k, v in group_meta ~}
${k} = ${jsonencode(v)}
%{ endfor ~}
}
%{ endif ~}
%{ if sticky_disk ~}
ephemeral_disk {
migrate = true
@ -113,6 +121,14 @@ job "${name}" {
task "${name}" {
driver = "docker"
%{ if length(meta) > 0 ~}
meta = {
%{ for k, v in meta ~}
${k} = ${jsonencode(v)}
%{ endfor ~}
}
%{ endif ~}
config {
image = "${image}"
%{ if service_port != null ~}

View File

@ -8,6 +8,18 @@ variable "image" {
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" {
type = number
default = null