Nomad HCL2 Function Examples

Hi @jeff.couvrette and thanks for the question.

One use case which I have personally had in the past is injecting Docker image tags within CI systems, where an application build triggers a downsteam deployment and passes it the newly produced version identifier to deploy.

A example job specification for how this might look would be as follows:

variable "image_version" {
 type    = string
 default = "latest"
}

job "example" {
  datacenters = ["dc1"]

  group "cache" {
    network {
      port "db" {
        to = 6379
      }
    }

    task "redis" {
      driver = "docker"

      config {
        image = format("redis:%s", var.image_version)
        ports = ["db"]
      }

      resources {
        cpu    = 500
        memory = 256
      }
    }
  }
}

The job can then be deployed to Nomad using a non-default image version using the nomad job run -var="image_version=4.0" example.nomad command.

Please let me know if you have any other questions or follow up.

Thanks,
jrasell and the Nomad team.

3 Likes