Hey folks
I am having some trouble figuring out when and where I can use interpolation of the temporary iterator variable in dynamic blocks.
I want to utilize dynamic blocks in order to automagically generate task groups and task definitions. Take a look at the job below - essentially I need to provide the current value of the temporary iterator variable as an argument to the Docker container but no matter what I have tried I have been unsuccessful so far
It works fine here :
labels = ["prom-exporter-${ip.value}"]
but this simply refuses to interpret the variable ${ip.value}
:
...
config {
image = "quay.io/citrix/citrix-adc-metrics-exporter:1.4.6"
args = [
"--target-nsip=${ip.value}",
"--port=${NOMAD_PORT_http}"
]
...
nomad validate
and nomad plan
both accept the job without any complaints but interpolation does not happen as the container literally receives --target-nsip=${ip.value}
as it’s input
The full jobfile :
variables {
netscaler_endpoints = ["1.2.3.4", "4.5.6.7", "8.9.10.11"]
}
job "netscaler-prometheus" {
datacenters = ["dc1"]
namespace = "whatever"
constraint {
attribute = "${attr.nomad.version}"
operator = "semver"
value = ">= 1.0.0"
}
dynamic "group" {
for_each = var.netscaler_endpoints
iterator = ip
labels = ["prom-exporter-${ip.value}"]
content {
network {
port "http" {}
dns {
servers = ["10.10.10.10"]
}
}
task "prom-exporter" {
driver = "docker"
config {
image = "quay.io/citrix/citrix-adc-metrics-exporter:1.4.6"
args = [
"--target-nsip=${ip.value}",
"--port=${NOMAD_PORT_http}"
]
ports = ["http"]
}
service {
name = "prom-exporter"
port = "http"
check {
type = "http"
port = "http"
path = "/"
interval = "5s"
timeout = "3s"
}
}
resources {
cpu = 500
memory = 256
}
} # task ends here
} # content block ends here
} # dynamic block ends here
} # job ends here