Hey all,
I am starting to work on a nomad cluster for our services (trying to keep it minimal by not using vault or consul in the first iteration).
Currently, am researching what the best way would be to control/deploy nomad jobs and variables.
My first approach was:
- a jobs folder containing all job files
- a variables folder containing all variables files
- use ansible to upload these files to one of the nodes
- then use ansible to iterate through these and execute
nomad job run ...
/nomad var put -force @...
on that node
The ansible code for that is pretty minimal and it works fine. It also gives me the added benefit of using ansible-vault
to encrypt the variables file in case these contain sensitive data.
But I just did a try with the terraform nomad provider to see how it compares. Note that I am aware that this provider does not yet support nomad variables (I saw a MR was created for it).
I used following simple approach (we enabled ACL’s):
variable "nomad_token" {
sensitive = true
}
provider "nomad" {
address = "http://<some_host>:4646"
secret_id = var.nomad_token
}
variable "jobs_folder" {
type = string
}
resource "nomad_job" "job" {
for_each = fileset(var.jobs_folder, "**/*.nomad")
jobspec = file("${var.jobs_folder}/${each.value}")
purge_on_destroy = true
hcl2 {
enabled = true
allow_fs = true
vars = {
nomad_token = var.nomad_token
}
}
}
I like the fact that using the teraform provider gives a state, which makes removing/purging jobs (by renaming/deleting job files) much easier. On top of that it gives the benefit of managing other resources like volumes/acl’s etc…
It is also much faster (as it doesn’t have the ssh/ansible connection overhead).
So here my first question:
Some of our jobs will need the nomad ACL token (var.nomad_token
). For example the traefik job needs it for service auto-discovery via nomad API.
By using the approach with the code above, it seems I need to declare the nomad_token
as input variable in every job. Is there any way to avoid that? Assuming I would like to keep it generic and treat every job file the same way.
My second question would be:
How are others managing the deployment of jobs in a production environment? I haven’t found many resources regarding that (or missed them).
Thanks in advance!
~