Skip to content

Commit

Permalink
feat: add external lb
Browse files Browse the repository at this point in the history
  • Loading branch information
Denise Perez committed Jun 27, 2024
1 parent 81a0253 commit a981f50
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 12 deletions.
2 changes: 1 addition & 1 deletion clients.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module "clients" {
vm_identity_name = var.client_identity_name
frontend_container_cores_num = var.clients_use_dpdk ? var.client_frontend_cores : 1
instance_type = var.client_instance_type
backend_lb_ip = var.create_lb ? azurerm_lb.backend_lb[0].private_ip_address : ""
backend_lb_ip = var.create_lb ? var.assign_public_ip ? azurerm_public_ip.backend_ip[0].ip_address : azurerm_lb.backend_lb[0].private_ip_address : ""
ssh_public_key = var.ssh_public_key == null ? tls_private_key.ssh_key[0].public_key_openssh : var.ssh_public_key
ppg_id = var.client_placement_group_id == "" ? local.placement_group_id : var.client_placement_group_id
assign_public_ip = local.assign_public_ip
Expand Down
65 changes: 54 additions & 11 deletions lb.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
locals {
lb_external_ip = var.assign_public_ip ? 1 : 0
}
# ================= ui lb =========================== #
resource "azurerm_public_ip" "ui_ip" {
count = var.assign_public_ip ? 1 : 0
name = "${var.prefix}-${var.cluster_name}-ui-public-ip"
location = local.location
resource_group_name = local.resource_group_name
allocation_method = "Static"
sku = "Standard"
}

resource "azurerm_lb" "ui_lb" {
count = var.create_lb ? 1 : 0
name = "${var.prefix}-${var.cluster_name}-ui-lb"
resource_group_name = var.rg_name
location = data.azurerm_resource_group.rg.location
sku = "Standard"
frontend_ip_configuration {
name = "${var.prefix}-${var.cluster_name}-ui-lb-frontend"
subnet_id = data.azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
private_ip_address_version = "IPv4"
dynamic "frontend_ip_configuration" {
for_each = range(0, local.lb_external_ip)
content {
name = "${var.prefix}-${var.cluster_name}-public-ui-frontend"
public_ip_address_id = azurerm_public_ip.ui_ip[0].id

}
}
dynamic "frontend_ip_configuration" {
for_each = range(local.lb_external_ip, 1)
content {
name = "${var.prefix}-${var.cluster_name}-ui-lb-frontend"
subnet_id = data.azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
private_ip_address_version = "IPv4"
}
}

tags = merge(var.tags_map, { "weka_cluster" : var.cluster_name })
lifecycle {
ignore_changes = [tags]
Expand Down Expand Up @@ -53,18 +77,37 @@ resource "azurerm_lb_rule" "ui_lb_rule" {
}

# ================= backend lb =========================== #
resource "azurerm_public_ip" "backend_ip" {
count = var.assign_public_ip ? 1 : 0
name = "${var.prefix}-${var.cluster_name}-backend-public-ip"
location = local.location
resource_group_name = local.resource_group_name
allocation_method = "Static"
sku = "Standard"
}

resource "azurerm_lb" "backend_lb" {
count = var.create_lb ? 1 : 0
name = "${var.prefix}-${var.cluster_name}-backend-lb"
resource_group_name = var.rg_name
location = data.azurerm_resource_group.rg.location
sku = "Standard"
tags = merge(var.tags_map, { "weka_cluster" : var.cluster_name })
frontend_ip_configuration {
name = "${var.prefix}-${var.cluster_name}-backend-lb-frontend"
subnet_id = data.azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
private_ip_address_version = "IPv4"
dynamic "frontend_ip_configuration" {
for_each = range(0, local.lb_external_ip)
content {
name = "${var.prefix}-${var.cluster_name}-public-backend-frontend"
public_ip_address_id = azurerm_public_ip.backend_ip[0].id
}
}
dynamic "frontend_ip_configuration" {
for_each = range(local.lb_external_ip, 1)
content {
name = "${var.prefix}-${var.cluster_name}-backend-lb-frontend"
subnet_id = data.azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
private_ip_address_version = "IPv4"
}
}
lifecycle {
ignore_changes = [tags]
Expand Down Expand Up @@ -107,7 +150,7 @@ resource "azurerm_lb_rule" "backend_lb_rule" {
}

resource "azurerm_private_dns_a_record" "dns_a_record_backend_lb" {
count = var.create_lb ? 1 : 0
count = var.create_lb && !var.assign_public_ip ? 1 : 0
name = lower("${var.cluster_name}-backend")
zone_name = local.private_dns_zone_name
resource_group_name = local.private_dns_rg_name
Expand Down

0 comments on commit a981f50

Please sign in to comment.