# HCL2 temporary iterator variable interpolation?

**URL:** <https://discuss.hashicorp.com/t/hcl2-temporary-iterator-variable-interpolation/20053>\
**Category:** Nomad\
**Created:** [January 22, 2021, 8:05pm UTC](https://discuss.hashicorp.com/t/hcl2-temporary-iterator-variable-interpolation/20053 "2021-01-22T20:05:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![henrikjohansen](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/henrikjohansen/32/16670_2.png) [@henrikjohansen](https://discuss.hashicorp.com/u/henrikjohansen)\
**Post date:** [January 22, 2021, 8:05pm UTC](https://discuss.hashicorp.com/t/hcl2-temporary-iterator-variable-interpolation/20053/1 "2021-01-22T20:05:53Z")

</div>

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}`:

```auto
   ...
	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 :

```auto
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

```

---

<div class="post-metadata">

**Author:** ![tgross](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tgross/32/3015_2.png) [@tgross](https://discuss.hashicorp.com/u/tgross)\
**Post date:** [January 22, 2021, 8:45pm UTC](https://discuss.hashicorp.com/t/hcl2-temporary-iterator-variable-interpolation/20053/2 "2021-01-22T20:45:11Z")

</div>

Hi @henrikjohansen! It looks like you’ve just run into [nomad/#9871](https://github.com/hashicorp/nomad/issues/9871). I’ll drop your example in that issue as well, for our investigation.

---

<div class="post-metadata">

**Author:** ![henrikjohansen](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/henrikjohansen/32/16670_2.png) [@henrikjohansen](https://discuss.hashicorp.com/u/henrikjohansen)\
**Post date:** [January 22, 2021, 9:12pm UTC](https://discuss.hashicorp.com/t/hcl2-temporary-iterator-variable-interpolation/20053/3 "2021-01-22T21:12:52Z")

</div>

Hey @tgross 👋 Thanks for letting me know - I’ll keep an eye on the GH issue 👍
