Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declarative interface #368

Open
thomaslepoix opened this issue Jun 29, 2023 · 1 comment
Open

Declarative interface #368

thomaslepoix opened this issue Jun 29, 2023 · 1 comment

Comments

@thomaslepoix
Copy link

Hello, I am really interested in using a registry of nomad jobs, but I am not interested in deploying jobs through imperative commands such as nomad-pack run <pack>. I'd rather not deviate from my current flow where all my jobs are described in files, deployed thanks to Terraform -> everything as code.

Is there any plan to make nomad-pack available from either one of the following way?

  • Directly from Nomad jobspec files
  • From the Nomad Terraform provider
  • From a dedicated Nomad-pack Terraform provider

By the way, I would be glad to use the nomad-pack CLI for various other tasks such as consulting registry list, generating pack from template, and so on.

@Jamesits
Copy link

Jamesits commented Apr 29, 2024

Beside the user interface part, there is a serious problem on the current nomad-pack impl: if a job is removed from a pack, nomad-pack run xxx will not remove it from the deployment. (I've created a separate issue: #503)

But you don't need nomad-pack! It is possible to implement most nomad-pack features in Terraform's Nomad provider:

Here's some demo that you can try out.

Job File Templating

Terraform:

resource "nomad_job" "xxx" {
  jobspec = templatefile("${path.module}/job.nomad.hcl.tftpl", {
    "key" = "value",
  })
  hcl2 {}
  purge_on_destroy = true
}

Template:

job "name-${key}" {
 // ...
}

(Escape all $ in the job template as $$)

Pseudo "Pack" UI on Nomad

Just inject the relevant meta values by hand.

job "hello_world" {
  type      = "service"
  namespace = "default"

  meta = {
    "pack.deployment_name" = "hello_world"
    "pack.job" = "hello_world"
    "pack.name" = "hello_world"
    "pack.path" = "/nonexistent"
    "pack.registry" = "<<local folder>>"
    "pack.version" = "<<none>>"
  }

  group "hello" {
    task "hello" {
      driver = "docker"

      config {
        image = "k8s.gcr.io/pause:3.2"
      }

      resources {
        cpu        = 100
        memory     = 100
        memory_max = 250
      }
    }
  }
}

Reusable Packs

Use either Terraform modules in a git repository, or Terragrunt. It works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants