2023-11-29 18:01:34 +01:00
|
|
|
# Main load balancer. L4, backed by Octavia
|
|
|
|
resource "openstack_lb_loadbalancer_v2" "main_lb" {
|
2023-11-30 19:48:49 +01:00
|
|
|
vip_subnet_id = var.main_private_subnet_id
|
|
|
|
name = var.octavia_information.main_lb_name
|
|
|
|
description = var.octavia_information.main_lb_description
|
|
|
|
flavor_id = var.octavia_information.octavia_flavor_id
|
|
|
|
vip_address = var.basic_services_ip.octavia_main
|
2024-01-11 19:13:41 +01:00
|
|
|
# availability_zone = var.availability_zones_names.availability_zone_no_gpu
|
2023-11-30 19:48:49 +01:00
|
|
|
loadbalancer_provider = "amphora"
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Allocate a floating IP
|
|
|
|
resource "openstack_networking_floatingip_v2" "main_lb_ip" {
|
2023-11-30 19:48:49 +01:00
|
|
|
pool = var.floating_ip_pools.main_public_ip_pool
|
|
|
|
# The DNS association does not work because of a bug in the OpenStack API
|
|
|
|
# dns_name = "main-lb"
|
|
|
|
# dns_domain = var.dns_zone.zone_name
|
|
|
|
description = var.octavia_information.main_lb_description
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_networking_floatingip_associate_v2" "main_lb" {
|
2023-11-30 19:48:49 +01:00
|
|
|
floating_ip = openstack_networking_floatingip_v2.main_lb_ip.address
|
|
|
|
port_id = openstack_lb_loadbalancer_v2.main_lb.vip_port_id
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
2023-11-30 19:48:49 +01:00
|
|
|
recordset_name = "${var.octavia_information.main_lb_hostname}.${var.dns_zone.zone_name}"
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_dns_recordset_v2" "main_lb_dns_recordset" {
|
2023-11-30 19:48:49 +01:00
|
|
|
zone_id = var.dns_zone_id
|
2023-11-29 18:01:34 +01:00
|
|
|
name = local.recordset_name
|
|
|
|
description = "Public IP address of the main load balancer"
|
|
|
|
ttl = 8600
|
|
|
|
type = "A"
|
|
|
|
records = [openstack_networking_floatingip_v2.main_lb_ip.address]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Main HAPROXY stats listener
|
|
|
|
resource "openstack_lb_listener_v2" "main_haproxy_stats_listener" {
|
2023-11-30 19:48:49 +01:00
|
|
|
loadbalancer_id = openstack_lb_loadbalancer_v2.main_lb.id
|
|
|
|
protocol = "TCP"
|
|
|
|
protocol_port = 8880
|
|
|
|
description = "Listener for the stats of the main HAPROXY instances"
|
|
|
|
name = "main_haproxy_stats_listener"
|
|
|
|
allowed_cidrs = [var.ssh_sources.d4s_vpn_1_cidr, var.ssh_sources.d4s_vpn_2_cidr, var.ssh_sources.s2i2s_vpn_1_cidr, var.ssh_sources.s2i2s_vpn_2_cidr]
|
|
|
|
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_lb_pool_v2" "main_haproxy_stats_pool" {
|
2023-11-30 19:48:49 +01:00
|
|
|
listener_id = openstack_lb_listener_v2.main_haproxy_stats_listener.id
|
|
|
|
protocol = "TCP"
|
|
|
|
lb_method = "LEAST_CONNECTIONS"
|
|
|
|
name = "main-haproxy-lb-stats"
|
|
|
|
description = "Pool for the stats of the main HAPROXY instances"
|
|
|
|
persistence {
|
|
|
|
type = "SOURCE_IP"
|
|
|
|
}
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_lb_members_v2" "main_haproxy_stats_pool_members" {
|
2023-11-30 19:48:49 +01:00
|
|
|
pool_id = openstack_lb_pool_v2.main_haproxy_stats_pool.id
|
|
|
|
member {
|
|
|
|
name = "haproxy l7 1"
|
|
|
|
address = var.basic_services_ip.haproxy_l7_1
|
|
|
|
protocol_port = 8880
|
|
|
|
}
|
|
|
|
member {
|
|
|
|
name = "haproxy l7 2"
|
|
|
|
address = var.basic_services_ip.haproxy_l7_2
|
|
|
|
protocol_port = 8880
|
|
|
|
}
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_lb_monitor_v2" "main_haproxy_stats_monitor" {
|
2023-11-30 19:48:49 +01:00
|
|
|
pool_id = openstack_lb_pool_v2.main_haproxy_stats_pool.id
|
|
|
|
name = "main_haproxy_stats_monitor"
|
|
|
|
type = "TCP"
|
|
|
|
delay = 20
|
|
|
|
timeout = 5
|
|
|
|
max_retries = 3
|
|
|
|
admin_state_up = true
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Main HAPROXY HTTP
|
|
|
|
resource "openstack_lb_listener_v2" "main_haproxy_http_listener" {
|
2023-11-30 19:48:49 +01:00
|
|
|
loadbalancer_id = openstack_lb_loadbalancer_v2.main_lb.id
|
|
|
|
protocol = "TCP"
|
|
|
|
protocol_port = 80
|
|
|
|
description = "HTTP listener of the main HAPROXY instances"
|
|
|
|
name = "main_haproxy_http_listener"
|
|
|
|
admin_state_up = true
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_lb_pool_v2" "main_haproxy_http_pool" {
|
2023-11-30 19:48:49 +01:00
|
|
|
listener_id = openstack_lb_listener_v2.main_haproxy_http_listener.id
|
|
|
|
protocol = "PROXYV2"
|
|
|
|
lb_method = "LEAST_CONNECTIONS"
|
|
|
|
name = "main-haproxy-lb-http"
|
|
|
|
description = "Pool for the HTTP listener of the main HAPROXY instances"
|
|
|
|
persistence {
|
|
|
|
type = "SOURCE_IP"
|
|
|
|
}
|
|
|
|
admin_state_up = true
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_lb_members_v2" "main_haproxy_http_pool_members" {
|
2023-11-30 19:48:49 +01:00
|
|
|
pool_id = openstack_lb_pool_v2.main_haproxy_http_pool.id
|
|
|
|
member {
|
|
|
|
name = "haproxy l7 1"
|
|
|
|
address = var.basic_services_ip.haproxy_l7_1
|
|
|
|
protocol_port = 80
|
|
|
|
}
|
|
|
|
member {
|
|
|
|
name = "haproxy l7 2"
|
|
|
|
address = var.basic_services_ip.haproxy_l7_2
|
|
|
|
protocol_port = 80
|
|
|
|
}
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_lb_monitor_v2" "main_haproxy_http_monitor" {
|
2023-11-30 19:48:49 +01:00
|
|
|
pool_id = openstack_lb_pool_v2.main_haproxy_http_pool.id
|
|
|
|
name = "main_haproxy_http_monitor"
|
|
|
|
type = "HTTP"
|
|
|
|
http_method = "GET"
|
|
|
|
url_path = "/_haproxy_health_check"
|
|
|
|
expected_codes = "200"
|
|
|
|
delay = 20
|
|
|
|
timeout = 5
|
|
|
|
max_retries = 3
|
|
|
|
admin_state_up = true
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Main HAPROXY HTTPS
|
|
|
|
resource "openstack_lb_listener_v2" "main_haproxy_https_listener" {
|
2023-11-30 19:48:49 +01:00
|
|
|
loadbalancer_id = openstack_lb_loadbalancer_v2.main_lb.id
|
|
|
|
protocol = "TCP"
|
|
|
|
protocol_port = 443
|
|
|
|
description = "HTTPS listener of the main HAPROXY instances"
|
|
|
|
name = "main_haproxy_https_listener"
|
|
|
|
admin_state_up = true
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_lb_pool_v2" "main_haproxy_https_pool" {
|
2023-11-30 19:48:49 +01:00
|
|
|
listener_id = openstack_lb_listener_v2.main_haproxy_https_listener.id
|
|
|
|
protocol = "PROXYV2"
|
|
|
|
lb_method = "LEAST_CONNECTIONS"
|
|
|
|
name = "main-haproxy-lb-https"
|
|
|
|
description = "Pool for the HTTPS listener of the main HAPROXY instances"
|
|
|
|
persistence {
|
|
|
|
type = "SOURCE_IP"
|
|
|
|
}
|
|
|
|
admin_state_up = true
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_lb_members_v2" "main_haproxy_https_pool_members" {
|
2023-11-30 19:48:49 +01:00
|
|
|
pool_id = openstack_lb_pool_v2.main_haproxy_https_pool.id
|
|
|
|
member {
|
|
|
|
name = "haproxy l7 1"
|
|
|
|
address = var.basic_services_ip.haproxy_l7_1
|
|
|
|
protocol_port = 443
|
|
|
|
}
|
|
|
|
member {
|
|
|
|
name = "haproxy l7 2"
|
|
|
|
address = var.basic_services_ip.haproxy_l7_2
|
|
|
|
protocol_port = 443
|
|
|
|
}
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_lb_monitor_v2" "main_haproxy_https_monitor" {
|
2023-11-30 19:48:49 +01:00
|
|
|
pool_id = openstack_lb_pool_v2.main_haproxy_https_pool.id
|
|
|
|
name = "main_haproxy_https_monitor"
|
|
|
|
type = "HTTPS"
|
|
|
|
http_method = "GET"
|
|
|
|
url_path = "/_haproxy_health_check"
|
|
|
|
expected_codes = "200"
|
|
|
|
delay = 20
|
|
|
|
timeout = 5
|
|
|
|
max_retries = 3
|
|
|
|
admin_state_up = true
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
output "main_loadbalancer_ip" {
|
|
|
|
description = "Main Load balancer IP address"
|
|
|
|
value = openstack_lb_loadbalancer_v2.main_lb.vip_address
|
|
|
|
}
|
|
|
|
|