Skip to content

Instantly share code, notes, and snippets.

@blinkinglight
Forked from Gurpartap/job.nomad.hcl
Created January 24, 2023 06:50
Show Gist options
  • Save blinkinglight/e018af7be7fe0ddc4aa77f28567668e1 to your computer and use it in GitHub Desktop.
Save blinkinglight/e018af7be7fe0ddc4aa77f28567668e1 to your computer and use it in GitHub Desktop.
nomad + consul template comma separated services from tags
job web {
datacenters = ["dc1"]
type = "service"
priority = 70
group app {
count = 1
task env {
driver = "exec"
config {
command = "/usr/bin/env"
}
template {
env = true
destination = "${NOMAD_SECRETS_DIR}/env"
data = <<EOF
SERVICES_FROM_TAG={{range services}}{{if in .Tags "tag-name-goes-here"}}{{$services:=service .Name "any"}}{{if gt (len $services) 0}}{{range $services}}{{.Address}}:{{.Port}},{{end}}{{end}}{{end}}{{end}}
EOF
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment