forked from Azure/terraform-azurerm-loadbalancer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
73 lines (66 loc) · 3.33 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Azure load balancer module
data "azurerm_resource_group" "azlb" {
name = var.resource_group_name
}
resource "azurerm_public_ip" "azlb" {
count = var.type == "public" ? 1 : 0
name = "${var.prefix}-publicIP"
resource_group_name = data.azurerm_resource_group.azlb.name
location = coalesce(var.location, data.azurerm_resource_group.azlb.location)
allocation_method = var.allocation_method
sku = var.pip_sku
tags = var.tags
}
resource "azurerm_lb" "azlb" {
name = "${var.prefix}-lb"
resource_group_name = data.azurerm_resource_group.azlb.name
location = coalesce(var.location, data.azurerm_resource_group.azlb.location)
sku = var.lb_sku
tags = var.tags
frontend_ip_configuration {
name = var.frontend_name
public_ip_address_id = var.type == "public" ? join("", azurerm_public_ip.azlb.*.id) : ""
subnet_id = var.frontend_subnet_id
private_ip_address = var.frontend_private_ip_address
private_ip_address_allocation = var.frontend_private_ip_address_allocation
}
}
resource "azurerm_lb_backend_address_pool" "azlb" {
name = "BackEndAddressPool"
loadbalancer_id = azurerm_lb.azlb.id
}
resource "azurerm_lb_nat_rule" "azlb" {
count = length(var.remote_port)
name = "VM-${count.index}"
resource_group_name = data.azurerm_resource_group.azlb.name
loadbalancer_id = azurerm_lb.azlb.id
protocol = "tcp"
frontend_port = "5000${count.index + 1}"
backend_port = element(var.remote_port[element(keys(var.remote_port), count.index)], 1)
frontend_ip_configuration_name = var.frontend_name
}
resource "azurerm_lb_probe" "azlb" {
count = length(var.lb_probe)
name = element(keys(var.lb_probe), count.index)
resource_group_name = data.azurerm_resource_group.azlb.name
loadbalancer_id = azurerm_lb.azlb.id
protocol = element(var.lb_probe[element(keys(var.lb_probe), count.index)], 0)
port = element(var.lb_probe[element(keys(var.lb_probe), count.index)], 1)
interval_in_seconds = var.lb_probe_interval
number_of_probes = var.lb_probe_unhealthy_threshold
request_path = element(var.lb_probe[element(keys(var.lb_probe), count.index)], 2)
}
resource "azurerm_lb_rule" "azlb" {
count = length(var.lb_port)
name = element(keys(var.lb_port), count.index)
resource_group_name = data.azurerm_resource_group.azlb.name
loadbalancer_id = azurerm_lb.azlb.id
protocol = element(var.lb_port[element(keys(var.lb_port), count.index)], 1)
frontend_port = element(var.lb_port[element(keys(var.lb_port), count.index)], 0)
backend_port = element(var.lb_port[element(keys(var.lb_port), count.index)], 2)
frontend_ip_configuration_name = var.frontend_name
enable_floating_ip = false
backend_address_pool_id = azurerm_lb_backend_address_pool.azlb.id
idle_timeout_in_minutes = 5
probe_id = element(azurerm_lb_probe.azlb.*.id, count.index)
}