job "vault-dev-warden" {
  datacenters = ["dc1"]
  type = "service"

  group "vault-dev" {
    count = 1

    # 约束到有consul的节点
    constraint {
      attribute = "${meta.consul}"
      operator  = "="
      value     = "true"
    }

    network {
      port "http" {
        to = 8200
      }
      port "cluster" {
        to = 8201
      }
    }

    service {
      name = "vault-dev"
      port = "http"
    
      check {
        type     = "http"
        path     = "/v1/sys/health"
        interval = "10s"
        timeout  = "5s"
      }
    }

    task "vault-dev" {
      driver = "raw_exec"

      config {
        command = "vault"
        args = [
          "server",
          "-dev",
          "-dev-listen-address=0.0.0.0:8200",
          "-dev-root-token-id=root"
        ]
      }

      env {
        VAULT_ADDR = "http://127.0.0.1:8200"
        VAULT_TOKEN = "root"
      }

      resources {
        cpu    = 500
        memory = 512
      }

      logs {
        max_files     = 10
        max_file_size = 10
      }
    }
  }
}