Skip to content

Nomad Cluster

The nomad_cluster resource creates HashiCorp Nomad clusters as Docker containers. Nomad clusters can be configured as single-node combined server/client instances or multi-node setups with dedicated server and client nodes.

resource "nomad_cluster" "name" {
network {
id = resource.network.main
}
}
resource "nomad_cluster" "name" {
# Network configuration
network {
id = resource.network.main
ip_address = "10.0.0.10"
aliases = ["nomad", "server"]
}
# Optional cluster configuration
client_nodes = 3
datacenter = "dc1"
environment = {
NOMAD_LOG_LEVEL = "INFO"
CUSTOM_VAR = "value"
}
# Configuration files
server_config = "./nomad/server.hcl"
client_config = "./nomad/client.hcl"
consul_config = "./consul/config.hcl"
# Image configuration
image {
name = "hashicorp/nomad:1.8.4"
username = "username"
password = "password"
}
# Volume mounts
volume {
source = "./nomad-data"
destination = "/opt/nomad/data"
type = "bind"
read_only = false
}
# Port mappings
port {
local = 4646
host = 4646
protocol = "tcp"
}
port_range {
local_range = "8000-8010"
host_range = "8000-8010"
protocol = "tcp"
}
# Image copying
copy_image {
name = "myapp:latest"
username = "registry_user"
password = "registry_pass"
}
# Driver configuration
config {
docker {
no_proxy = ["registry.local"]
insecure_registries = ["registry.local:5000"]
}
}
open_in_browser = false
}

Essential settings for the Nomad cluster.

FieldTypeRequiredDescription
networkblockNetwork attachments (repeatable)
client_nodesintNumber of dedicated client nodes (default: 0 = combined server/client)
datacenterstringNomad datacenter name (default: “dc1”)
environmentmap(string)Environment variables for all nodes (default: {})
server_configstringPath to custom server configuration file
client_configstringPath to custom client configuration file
consul_configstringPath to custom Consul configuration file
open_in_browserboolOpen Nomad UI in browser after creation (default: false)

Docker image settings for the cluster nodes.

FieldTypeRequiredDescription
imageblockDocker image configuration
↳ namestringDocker image name with tag (default: ghcr.io/jumppad-labs/nomad:v1.8.4)
↳ usernamestringUsername for private registry authentication
↳ passwordstringPassword for private registry authentication

Network attachment settings for cluster nodes.

FieldTypeRequiredDescription
networkblockNetwork attachments (repeatable)
↳ idreferenceReference to a network resource
↳ ip_addressstringStatic IP address for the server node (default: auto-assigned)
↳ aliaseslist(string)Network aliases for service discovery (default: [])

Volume mounts for persistent data and configuration.

FieldTypeRequiredDescription
volumeblockVolume mounts (repeatable)
↳ sourcestringSource path on host or volume name
↳ destinationstringMount path inside container
↳ typestringVolume type: “bind”, “volume”, or “tmpfs” (default: “bind”)
↳ read_onlyboolMount as read-only (default: false)
↳ bind_propagationstringBind propagation: “shared”, “private”, “slave”, “rslave”, “rprivate”
↳ bind_propagation_non_recursiveboolNon-recursive bind mount (default: false)
↳ selinux_relabelstringSELinux relabeling: “shared” or “private”

Port mappings and exposure settings.

FieldTypeRequiredDescription
portblockPort mappings (repeatable)
↳ localintContainer port
↳ hostintHost port (default: same as local)
↳ protocolstringProtocol: “tcp” or “udp” (default: “tcp”)
port_rangeblockPort range mappings (repeatable)
↳ local_rangestringContainer port range (e.g., “3000-3010”)
↳ host_rangestringHost port range (default: same as local_range)
↳ protocolstringProtocol: “tcp” or “udp” (default: “tcp”)

Docker images to copy to cluster nodes.

FieldTypeRequiredDescription
copy_imageblockImages to copy to cluster (repeatable)
↳ namestringDocker image name to copy from local cache
↳ usernamestringUsername for private registry
↳ passwordstringPassword for private registry

Configuration for Nomad task drivers.

FieldTypeRequiredDescription
configblockDriver configuration

config → docker

Configures Docker driver settings for the Nomad cluster.

FieldTypeRequiredDescription
dockerblockDocker driver configuration
↳ no_proxylist(string)Registries to exclude from image cache (default: [])
↳ insecure_registrieslist(string)Registries to treat as insecure (default: [])

These attributes are set by the system after the cluster is created:

FieldTypeDescription
external_ipstringIP address of the Nomad cluster
api_portintPort where the Nomad API is exposed (default: 4646)
connector_portintPort where the Jumppad connector runs
config_dirstringDirectory containing server and client configurations
server_container_namestringFully qualified container name for the server
client_container_namelist(string)Container names for client nodes (if any)
  • Configuration file paths are made absolute relative to the config file location
  • Network attachments must reference valid network resources
  • Client nodes value must be non-negative
  • Volume source paths must exist for bind mounts
  • Port mappings must use valid port numbers (1-65535)
resource "network" "nomad" {
subnet = "10.0.0.0/24"
}
resource "nomad_cluster" "dev" {
network {
id = resource.network.nomad
}
}
resource "network" "nomad" {
subnet = "10.0.0.0/24"
}
resource "nomad_cluster" "production" {
client_nodes = 3
datacenter = "east"
network {
id = resource.network.nomad
ip_address = "10.0.0.10"
aliases = ["nomad-server", "server"]
}
environment = {
NOMAD_LOG_LEVEL = "INFO"
DATACENTER = "east"
}
volume {
source = "./nomad-data"
destination = "/opt/nomad/data"
type = "bind"
}
port {
local = 4646
host = 4646
}
}
resource "nomad_cluster" "custom" {
client_nodes = 2
network {
id = resource.network.main
}
server_config = "./config/server.hcl"
client_config = "./config/client.hcl"
consul_config = "./config/consul.hcl"
config {
docker {
no_proxy = ["registry.internal.com"]
insecure_registries = ["registry.internal.com:5000"]
}
}
copy_image {
name = "myapp:latest"
}
copy_image {
name = "postgres:13"
}
volume {
source = "./nomad-jobs"
destination = "/opt/nomad/jobs"
type = "bind"
read_only = true
}
}
resource "nomad_cluster" "dev" {
network {
id = resource.network.dev
}
environment = {
NOMAD_LOG_LEVEL = "DEBUG"
}
port_range {
local_range = "8000-8010"
host_range = "8000-8010"
protocol = "tcp"
}
port {
local = 4646
host = 4646
}
open_in_browser = true
}

Nomad clusters are commonly used with nomad_job resources:

resource "nomad_cluster" "app" {
client_nodes = 2
network {
id = resource.network.app
}
}
resource "nomad_job" "web" {
cluster = resource.nomad_cluster.app
jobspec = <<-EOF
job "web" {
datacenters = ["dc1"]
group "web" {
count = 2
task "nginx" {
driver = "docker"
config {
image = "nginx:latest"
ports = ["http"]
}
resources {
cpu = 100
memory = 128
}
}
}
}
EOF
}
  1. Network Planning: Use dedicated networks for Nomad clusters to isolate traffic
  2. Resource Limits: Configure appropriate resource limits for production workloads
  3. Configuration Files: Use external configuration files for complex setups
  4. Data Persistence: Mount volumes for Nomad data directories in production
  5. Security: Use private registries and secure configuration for sensitive environments
  6. Monitoring: Expose necessary ports for monitoring and observability tools
  7. Image Management: Pre-load frequently used images using copy_image blocks
  1. Development Environment: Single-node clusters for local development
  2. CI/CD Pipeline: Multi-node clusters for testing deployment scenarios
  3. Learning Platform: Educational environments for HashiCorp Nomad training
  4. Microservices Testing: Container orchestration for complex application stacks
  5. Load Testing: Distributed workload execution across multiple nodes