Skip to content

Commit 16ca108

Browse files
authored
main
1 parent 7043f56 commit 16ca108

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

3_networking/load-balancer/main.tf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# main.tf
2+
# This file contains the main configuration for creating the Azure Load Balancer and its associated resources.
3+
4+
# Resource Group for Load Balancer
5+
resource "azurerm_resource_group" "lb" {
6+
name = var.resource_group_name
7+
location = var.location
8+
tags = var.tags
9+
}
10+
11+
# Public IP for Load Balancer
12+
resource "azurerm_public_ip" "lb" {
13+
name = var.public_ip_name
14+
location = azurerm_resource_group.lb.location
15+
resource_group_name = azurerm_resource_group.lb.name
16+
allocation_method = "Static"
17+
sku = var.lb_sku
18+
tags = var.tags
19+
}
20+
21+
# Azure Load Balancer
22+
resource "azurerm_lb" "lb" {
23+
name = var.load_balancer_name
24+
location = azurerm_resource_group.lb.location
25+
resource_group_name = azurerm_resource_group.lb.name
26+
sku = var.lb_sku
27+
28+
frontend_ip_configuration {
29+
name = var.frontend_ip_configuration_name
30+
public_ip_address_id = azurerm_public_ip.lb.id
31+
}
32+
33+
tags = var.tags
34+
}
35+
36+
# Backend Address Pool for Load Balancer
37+
resource "azurerm_lb_backend_address_pool" "lb" {
38+
name = var.backend_pool_name
39+
loadbalancer_id = azurerm_lb.lb.id
40+
}
41+
42+
# Health Probe for Load Balancer
43+
resource "azurerm_lb_probe" "lb" {
44+
name = var.health_probe_name
45+
loadbalancer_id = azurerm_lb.lb.id
46+
protocol = var.probe_protocol
47+
port = var.probe_port
48+
interval_in_seconds = 15
49+
number_of_probes = 2
50+
}
51+
52+
# Load Balancer Rule
53+
resource "azurerm_lb_rule" "lb" {
54+
name = var.lb_rule_name
55+
loadbalancer_id = azurerm_lb.lb.id
56+
protocol = "Tcp"
57+
frontend_port = var.frontend_port
58+
backend_port = var.backend_port
59+
frontend_ip_configuration_name = var.frontend_ip_configuration_name
60+
backend_address_pool_ids = [azurerm_lb_backend_address_pool.lb.id]
61+
probe_id = azurerm_lb_probe.lb.id
62+
enable_floating_ip = false
63+
idle_timeout_in_minutes = 4
64+
}

0 commit comments

Comments
 (0)