Skip to content

Commit

Permalink
wip - lb module
Browse files Browse the repository at this point in the history
  • Loading branch information
simu committed Aug 16, 2023
1 parent 72f204f commit 0e5ae50
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 7 deletions.
31 changes: 24 additions & 7 deletions lb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ module "lb" {
enable_proxy_protocol = var.lb_enable_proxy_protocol
}

module "lb_api" {
source = "./modules/cloudscale-lb"
cluster_id = var.cluster_id
region = var.region
protocol = "tcp"
subnet_uuid = local.subnet_uuid
members = module.master.ip_addresses[*]
port = 6443
health_check = {
type = "https"
path = "/readyz"
host = "api.${var.cluster_id}.${var.base_domain}"
}
}

/*
resource "cloudscale_load_balancer" "api" {
name = "${var.cluster_id}_api"
flavor_slug = "lb-standard"
Expand All @@ -33,13 +49,6 @@ resource "cloudscale_load_balancer_pool" "api" {
load_balancer_uuid = cloudscale_load_balancer.api.id
}
resource "cloudscale_load_balancer_listener" "api_k8s" {
name = "${var.cluster_id}_api-k8s"
pool_uuid = cloudscale_load_balancer_pool.api.id
protocol = "tcp"
protocol_port = 6443
}

resource "cloudscale_load_balancer_pool_member" "api" {
count = length(module.master.ip_addresses)
name = "${var.cluster_id}_api-member-${count.index}"
Expand All @@ -49,9 +58,17 @@ resource "cloudscale_load_balancer_pool_member" "api" {
subnet_uuid = local.subnet_uuid
}
resource "cloudscale_load_balancer_listener" "api_k8s" {
name = "${var.cluster_id}_api-k8s"
pool_uuid = cloudscale_load_balancer_pool.api.id
protocol = "tcp"
protocol_port = 6443
}
resource "cloudscale_load_balancer_health_monitor" "api" {
pool_uuid = cloudscale_load_balancer_pool.api.id
type = "https"
http_url_path = "/readyz"
http_host = "api.${var.cluster_id}.${var.base_domain}"
}
*/
36 changes: 36 additions & 0 deletions modules/cloudscale-lb/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resource "cloudscale_load_balancer" "lb" {
name = "${var.cluster_id}_${var.role}"
flavor_slug = "lb-standard"
zone_slug = "${var.region}1"
}

resource "cloudscale_load_balancer_pool" "api" {
name = "${var.cluster_id}_${var_role}"
algorithm = "round_robin"
protocol = var.protocol
load_balancer_uuid = cloudscale_load_balancer.lb.id
}

resource "cloudscale_load_balancer_pool_member" "lb" {
count = length(var.members)
name = "${var.cluster_id}_api-member-${count.index}"
pool_uuid = cloudscale_load_balancer_pool.api.id
protocol_port = var.port
address = var.members[count.index]
subnet_uuid = var.subnet_uuid
monitor_port = var.health_check.port
}

resource "cloudscale_load_balancer_listener" "lb" {
name = "${var.cluster_id}_${var.role}_${var.port}"
pool_uuid = cloudscale_load_balancer_pool.lb.id
protocol = var.protocol
protocol_port = var.port
}

resource "cloudscale_load_balancer_health_monitor" "lb" {
pool_uuid = cloudscale_load_balancer_pool.lb.id
type = var.health_check.type
http_url_path = var.health_check.path
http_host = var.health_check.host
}
1 change: 1 addition & 0 deletions modules/cloudscale-lb/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

9 changes: 9 additions & 0 deletions modules/cloudscale-lb/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.3.0"
required_providers {
cloudscale = {
source = "cloudscale-ch/cloudscale"
version = "4.2.0"
}
}
}
36 changes: 36 additions & 0 deletions modules/cloudscale-lb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
variable "cluster_id" {
type = string
}

variable "role" {
type = string
}

variable "region" {
type = string
}

variable "protocol" {
type = string
}

variable "subnet_uuid" {
type = string
}

variable "members" {
type = list(string)
}

variable "port" {
type = number
}

variable "health_check" {
type = object({ type = string, path = string, host = string, port = optional(number) })
}

variable "internal_vip" {
type = string
default = ""
}

0 comments on commit 0e5ae50

Please sign in to comment.