2
votes

I am beginner and I have problem to find solution for Terraform and Nomad. I need run Nomad and hashi-ui for web management of Nomad. I try to setup and run Nomad server via terrafom. Hashi-ui I have like nomad job. Nomad server and Hashi-ui run well. Hashi-ui I run in docker. Now I need to create terraform file for automation initial setup and orchestrate nomad. My server running on Debian 8.

My terraform file nomad.tf:

# Configure the Nomad provider
provider "nomad" {
  address = "http://localhost:4646"
  region = "global"
# group = "server"
}

variable "version" {
  default = "latest"
}

data "template_file" "job" {
  template = "${file("./hashi-ui.nomad")}"

  vars {
    version = "${var.version}"
  }
}

# Register a job
resource "nomad_job" "hashi-ui" {
  jobspec = "${data.template_file.job.rendered}"
}

And nomad job hashi-ui.nomad:

job "hashi-ui" {
  region      = "global"
  datacenters = ["dc1"]
  type        = "service"

  group "server" {
    count = 1

    task "hashi-ui" {
      driver = "docker"

      config {
        image        = "jippi/hashi-ui"
        network_mode = "host"
      }

      service {
        port = "http"

        check {
          type     = "http"
          path     = "/"
          interval = "10s"
          timeout  = "2s"
        }
      }

      env {
        NOMAD_ENABLE = 1
        NOMAD_ADDR   = "http://0.0.0.0:4646"
      }

      resources {
        cpu    = 500
        memory = 512

        network {
          mbits = 5

          port "http" {
            static = 3000
          }
        }
      }
    }
  }
}

Terraform plan shows changes, but terraform apply throws this error:

Error applying plan:

1 error(s) occurred:

Terraform does not automatically rollback in the face of errors. Instead, your Terraform state file has been partially updated with any resources that successfully completed. Please address the error above and apply again to incrementally change your infrastructure.

If I run nomad server beside than error is

1 error(s) occurred:

  • nomad_job.hashi-ui: 1 error(s) occurred:

  • nomad_job.hashi-ui: error applying jobspec: Unexpected response code: 500 (1 error(s) occurred:

  • Task group server validation failed: 1 error(s) occurred:

  • 2 error(s) occurred:

  • Max parallel can not be less than one: 0 < 1

  • Stagger must be greater than zero: 0s)

Can you help me please?

1

1 Answers

2
votes

You're missing a max parallel and stagger in your nomad job spec:

job "hashi-ui" {
  region      = "global"
  datacenters = ["dc1"]
  type        = "service"

  update {
    stagger      = "30s"
    max_parallel = 2
  }

  count = 1

  task "hashi-ui" {
    driver = "docker"

    config {
      image        = "jippi/hashi-ui"
      network_mode = "host"
    }
...