data "docker_registry_image" "unifi_controller" {
  name = "jacobalberty/unifi:v9"
}
resource "docker_service" "unifi_controller" {
  name     = "unifi_controller"
  provider = docker.unifi
  task_spec {
    container_spec {
      image = "${data.docker_registry_image.unifi_controller.name}@${data.docker_registry_image.unifi_controller.sha256_digest}"
      env = {
        TZ = "Europe/Amsterdam"
      }
      mounts {
        target = "/unifi"
        source = "/home/techinc/unifi"
        type   = "bind"
      }
    }
    restart_policy {
      condition = "any"
      delay     = "0s"
      window    = "0s"
    }
  }
  endpoint_spec {
    ports {
      target_port    = 8443
      published_port = 443
      publish_mode   = "ingress"
    }
    ports {
      target_port    = 8443
      published_port = 8443
      publish_mode   = "ingress"
    }
    ports {
      target_port    = 3478
      published_port = 3478
      publish_mode   = "ingress"
      protocol       = "udp"
    }
    ports {
      target_port    = 10001
      published_port = 10001
      publish_mode   = "ingress"
      protocol       = "udp"
    }
    ports {
      target_port    = 8080
      published_port = 8080
      publish_mode   = "ingress"
    }
  }
}

module "http2https" {
  providers  = { docker = docker.unifi }
  source     = "./lib/grey.ooo/products/iperf"
  stack_name = "network"
  ports      = [{ container = 80, host = 80, protocol = "tcp" }]
  //placement_constraints = local.placement_constraints.unifi
}
module "iperf" {
  providers  = { docker = docker.unifi }
  source     = "./lib/grey.ooo/products/http2https"
  stack_name = "network"
  ports      = [{ container = 5201, host = 5201, protocol = "tcp" }, { container = 5201, host = 5201, protocol = "udp" }]
  //placement_constraints = local.placement_constraints.unifi
}