variable "image_name" {
  type = string
  default = "docker.io/democraticcsi/democratic-csi:latest"
}

variable "csi_version" {
  type = string
  default = "1.5.0"
}

variable "config_data" {
  type = string
}

job "democratic-csi-nfs-controller" {
  datacenters = ["dc1"]

  group "controller" {
    task "plugin" {
      driver = "docker"

      config {
        image = var.image_name

        args = [
          "--csi-version=${var.csi_version}",
          # must match the csi_plugin.id attribute below
          "--csi-name=org.democratic-csi.nfs",
          "--driver-config-file=${NOMAD_TASK_DIR}/driver-config-file.yaml",
          "--log-level=info",
          "--csi-mode=controller",
          "--server-socket=/csi/csi.sock",
        ]
      }

      template {
        destination = "${NOMAD_TASK_DIR}/driver-config-file.yaml"

        data = var.config_data
      }

      csi_plugin {
        # must match --csi-name arg
        id        = "org.democratic-csi.nfs"
        type      = "controller"
        mount_dir = "/csi"
      }

      resources {
        cpu    = 250
        memory = 128
      }
    }
  }
}