Skip to content

Commit 0e5ae50

Browse files
committed
wip - lb module
1 parent 72f204f commit 0e5ae50

File tree

5 files changed

+106
-7
lines changed

5 files changed

+106
-7
lines changed

lb.tf

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ module "lb" {
2020
enable_proxy_protocol = var.lb_enable_proxy_protocol
2121
}
2222

23+
module "lb_api" {
24+
source = "./modules/cloudscale-lb"
25+
cluster_id = var.cluster_id
26+
region = var.region
27+
protocol = "tcp"
28+
subnet_uuid = local.subnet_uuid
29+
members = module.master.ip_addresses[*]
30+
port = 6443
31+
health_check = {
32+
type = "https"
33+
path = "/readyz"
34+
host = "api.${var.cluster_id}.${var.base_domain}"
35+
}
36+
}
37+
38+
/*
2339
resource "cloudscale_load_balancer" "api" {
2440
name = "${var.cluster_id}_api"
2541
flavor_slug = "lb-standard"
@@ -33,13 +49,6 @@ resource "cloudscale_load_balancer_pool" "api" {
3349
load_balancer_uuid = cloudscale_load_balancer.api.id
3450
}
3551
36-
resource "cloudscale_load_balancer_listener" "api_k8s" {
37-
name = "${var.cluster_id}_api-k8s"
38-
pool_uuid = cloudscale_load_balancer_pool.api.id
39-
protocol = "tcp"
40-
protocol_port = 6443
41-
}
42-
4352
resource "cloudscale_load_balancer_pool_member" "api" {
4453
count = length(module.master.ip_addresses)
4554
name = "${var.cluster_id}_api-member-${count.index}"
@@ -49,9 +58,17 @@ resource "cloudscale_load_balancer_pool_member" "api" {
4958
subnet_uuid = local.subnet_uuid
5059
}
5160
61+
resource "cloudscale_load_balancer_listener" "api_k8s" {
62+
name = "${var.cluster_id}_api-k8s"
63+
pool_uuid = cloudscale_load_balancer_pool.api.id
64+
protocol = "tcp"
65+
protocol_port = 6443
66+
}
67+
5268
resource "cloudscale_load_balancer_health_monitor" "api" {
5369
pool_uuid = cloudscale_load_balancer_pool.api.id
5470
type = "https"
5571
http_url_path = "/readyz"
5672
http_host = "api.${var.cluster_id}.${var.base_domain}"
5773
}
74+
*/

modules/cloudscale-lb/main.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
resource "cloudscale_load_balancer" "lb" {
2+
name = "${var.cluster_id}_${var.role}"
3+
flavor_slug = "lb-standard"
4+
zone_slug = "${var.region}1"
5+
}
6+
7+
resource "cloudscale_load_balancer_pool" "api" {
8+
name = "${var.cluster_id}_${var_role}"
9+
algorithm = "round_robin"
10+
protocol = var.protocol
11+
load_balancer_uuid = cloudscale_load_balancer.lb.id
12+
}
13+
14+
resource "cloudscale_load_balancer_pool_member" "lb" {
15+
count = length(var.members)
16+
name = "${var.cluster_id}_api-member-${count.index}"
17+
pool_uuid = cloudscale_load_balancer_pool.api.id
18+
protocol_port = var.port
19+
address = var.members[count.index]
20+
subnet_uuid = var.subnet_uuid
21+
monitor_port = var.health_check.port
22+
}
23+
24+
resource "cloudscale_load_balancer_listener" "lb" {
25+
name = "${var.cluster_id}_${var.role}_${var.port}"
26+
pool_uuid = cloudscale_load_balancer_pool.lb.id
27+
protocol = var.protocol
28+
protocol_port = var.port
29+
}
30+
31+
resource "cloudscale_load_balancer_health_monitor" "lb" {
32+
pool_uuid = cloudscale_load_balancer_pool.lb.id
33+
type = var.health_check.type
34+
http_url_path = var.health_check.path
35+
http_host = var.health_check.host
36+
}

modules/cloudscale-lb/output.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

modules/cloudscale-lb/providers.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_version = ">= 1.3.0"
3+
required_providers {
4+
cloudscale = {
5+
source = "cloudscale-ch/cloudscale"
6+
version = "4.2.0"
7+
}
8+
}
9+
}

modules/cloudscale-lb/variables.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
variable "cluster_id" {
2+
type = string
3+
}
4+
5+
variable "role" {
6+
type = string
7+
}
8+
9+
variable "region" {
10+
type = string
11+
}
12+
13+
variable "protocol" {
14+
type = string
15+
}
16+
17+
variable "subnet_uuid" {
18+
type = string
19+
}
20+
21+
variable "members" {
22+
type = list(string)
23+
}
24+
25+
variable "port" {
26+
type = number
27+
}
28+
29+
variable "health_check" {
30+
type = object({ type = string, path = string, host = string, port = optional(number) })
31+
}
32+
33+
variable "internal_vip" {
34+
type = string
35+
default = ""
36+
}

0 commit comments

Comments
 (0)