resource "ncloud_lb" "exem-dsk-lb" {
  name = "kube-api-server-lb"
  network_type = "PRIVATE"
  type = "NETWORK"
  subnet_no_list = [ ncloud_subnet.loadbalancer_subnet.subnet_no ]
}

resource "ncloud_lb_target_group" "exem-dsk-lb-group" {
  vpc_no = ncloud_vpc.exem-dsk-vpc.vpc_no
  protocol = "TCP"
  target_type = "VSVR"
  port = 6443

  health_check {
    protocol = "TCP"
    http_method = "GET"
    port = 6443
    #url_path = "/livez?verbose"
    cycle = 30
    up_threshold = 3
    down_threshold = 5
  }
  algorithm_type = "RR"
}

resource "ncloud_lb_target_group_attachment" "exem-dsk-lb-attach" {
  target_group_no = ncloud_lb_target_group.exem-dsk-lb-group.target_group_no
  target_no_list = [ ncloud_server.exem-dsk-master-1.instance_no, ncloud_server.exem-dsk-master-2.instance_no, ncloud_server.exem-dsk-master-3.instance_no ]
}

resource "ncloud_lb_listener" "exem-dsk-lb-listener" {
  load_balancer_no = ncloud_lb.exem-dsk-lb.load_balancer_no
  protocol = "TCP"
  port = 6443
  target_group_no = ncloud_lb_target_group.exem-dsk-lb-group.target_group_no
  #ssl_certificate_no = 20941
}