liveBook · Manning

HashiCorp Configuration Language

As explained in Road to Kubernetes

HCL, or HashiCorp Configuration Language, is a declarative configuration language for expressing structured settings and infrastructure definitions.

HashiCorp Configuration Language (HCL) is a declarative way to write configuration: you state the settings you want rather than a sequence of commands to produce them. Nomad uses HCL instead of YAML. Its syntax is closer to JSON, and the language is also used by Terraform and Vault. section 9.2

A first practical use is configuring a Nomad server. In /etc/nomad.d/nomad.hcl, assignments set values such as the data directory and bind address; blocks group related settings such as server and client behavior. The example enables one server and disables its client role. section 9.2.3

Listing 9.6 Nomad server configuration
# Located at /etc/nomad.d/nomad.hcl
data_dir = "/opt/nomad/data"

bind_addr = "0.0.0.0"

name = "nomad-server-1"

advertise {
    http = "192.168.204.96"
    rpc = "192.168.204.96"
    serf = "192.168.204.96"
}

server {
    enabled = true
    bootstrap_expect = 1 # number of servers
}

client {
    enabled = false
}

See how assignments and nested blocks combine in a server configuration. Replace the example’s advertised address with the server’s private IP address when configuring your cluster. section 9.2.3

To run a container, write a Nomad job in HCL. A job contains groups, and a group contains tasks. Each task can declare a Docker driver and the container image to run. Paste a job into the Nomad UI, select Plan to inspect what it intends to do, then select Run. section 9.2.5

Listing 9.8 Nomad job definition
job "a_unique_job_name" {
  group "unique_group_per_job" {
    task "unique_task_per_group" {
      driver = "docker"
      config {
        image = "codingforentrepreneurs/rk8s-py"
      }
    }
  }
}

Start with this small job definition to see the job → group → task structure and the Docker image declaration. section 9.2.5

The same structure can grow to run Python and Node.js containers in one group. Further declarations add network port mappings and service definitions. Those additions address a practical next problem: making running applications reachable. section 9.2.5

How Road to Kubernetes covers it

How deep it goes
Works through server settings and nested job definitions, but defers advanced server configuration and private-image setup.
Examples
Uses a Nomad server file and jobs for one container, then Python and Node.js containers with ports and services.
What it assumes
Starts with basic HCL declarations after virtual-machine setup; running the example job requires a Docker runtime and accessible container image.
What you can do after
Apply it via Nomad to configure a server and plan and run container jobs in its UI.
How it connects
Connects Nomad configuration to Docker containers, YAML, JSON, Terraform, and Vault.

Also explained in

Compare how 3 books explain HashiCorp Configuration Language →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.