-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadbalancers.tf
138 lines (119 loc) · 5.2 KB
/
loadbalancers.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
resource "azurerm_public_ip" "ingress" {
name = "ingress-lb-pip"
location = var.resource_location
resource_group_name = var.resource_group_name
allocation_method = "Static"
depends_on = [azurerm_resource_group.this]
sku = "Standard"
}
resource "azurerm_lb" "ingress" {
resource_group_name = var.resource_group_name
location = var.resource_location
name = "ingress-lb"
sku = "Standard"
frontend_ip_configuration {
name = "PublicIPAddress"
public_ip_address_id = azurerm_public_ip.ingress.id
}
depends_on = [azurerm_virtual_network.this]
}
resource "azurerm_lb_backend_address_pool" "ethernet0_1" {
name = "vmseries_ethernet0_1"
loadbalancer_id = azurerm_lb.ingress.id
depends_on = [azurerm_linux_virtual_machine.vmseries]
}
resource "azurerm_lb_probe" "ingress_https" {
name = "https"
resource_group_name = var.resource_group_name
loadbalancer_id = azurerm_lb.ingress.id
port = 443
protocol = "https"
request_path = "/php/login.php"
interval_in_seconds = 5
number_of_probes = 2
}
resource "azurerm_lb_rule" "tcp" {
count = length(var.inbound_tcp_ports)
name = "tcp-${element(var.inbound_tcp_ports, count.index)}"
resource_group_name = var.resource_group_name
loadbalancer_id = azurerm_lb.ingress.id
protocol = "TCP"
frontend_port = element(var.inbound_tcp_ports, count.index)
backend_port = element(var.inbound_tcp_ports, count.index)
frontend_ip_configuration_name = "PublicIPAddress"
backend_address_pool_id = azurerm_lb_backend_address_pool.ethernet0_1.id
probe_id = azurerm_lb_probe.ingress_https.id
enable_floating_ip = true
depends_on = [azurerm_lb.ingress, azurerm_lb_backend_address_pool.ethernet0_1]
disable_outbound_snat = true
}
resource "azurerm_lb_rule" "udp" {
count = length(var.inbound_udp_ports)
name = "udp-${element(var.inbound_udp_ports, count.index)}"
resource_group_name = var.resource_group_name
loadbalancer_id = azurerm_lb.ingress.id
protocol = "UDP"
frontend_port = element(var.inbound_udp_ports, count.index)
backend_port = element(var.inbound_udp_ports, count.index)
frontend_ip_configuration_name = "PublicIPAddress"
backend_address_pool_id = azurerm_lb_backend_address_pool.ethernet0_1.id
probe_id = azurerm_lb_probe.ingress_https.id
enable_floating_ip = true
depends_on = [azurerm_lb.ingress, azurerm_lb_backend_address_pool.ethernet0_1]
disable_outbound_snat = true
}
resource "azurerm_network_interface_backend_address_pool_association" "ethernet0_1" {
for_each = var.vmseries
network_interface_id = azurerm_network_interface.ethernet0_1[each.key].id
ip_configuration_name = "ipconfig1"
backend_address_pool_id = azurerm_lb_backend_address_pool.ethernet0_1.id
}
resource "azurerm_lb" "egress" {
resource_group_name = var.resource_group_name
location = var.resource_location
name = "egress-lb"
depends_on = [azurerm_virtual_network.this]
sku = "Standard"
frontend_ip_configuration {
name = "LoadBalancerIP"
subnet_id = azurerm_subnet.this["loadbalancer"].id
}
}
resource "azurerm_lb_probe" "egress_https" {
name = "https"
resource_group_name = var.resource_group_name
loadbalancer_id = azurerm_lb.egress.id
port = 443
protocol = "https"
request_path = "/php/login.php"
interval_in_seconds = 5
number_of_probes = 2
}
resource "azurerm_lb_backend_address_pool" "ethernet0_2" {
name = "ethernet0_2"
loadbalancer_id = azurerm_lb.egress.id
depends_on = [azurerm_linux_virtual_machine.vmseries]
}
resource "azurerm_lb_rule" "allports" {
name = "all-ports"
resource_group_name = var.resource_group_name
loadbalancer_id = azurerm_lb.egress.id
protocol = "All"
frontend_port = 0
backend_port = 0
frontend_ip_configuration_name = "LoadBalancerIP"
backend_address_pool_id = azurerm_lb_backend_address_pool.ethernet0_2.id
probe_id = azurerm_lb_probe.egress_https.id
enable_floating_ip = true
depends_on = [azurerm_network_interface.ethernet0_2]
}
resource "azurerm_network_interface_backend_address_pool_association" "ethernet0_2" {
for_each = var.vmseries
network_interface_id = azurerm_network_interface.ethernet0_2[each.key].id
ip_configuration_name = "ipconfig1"
backend_address_pool_id = azurerm_lb_backend_address_pool.ethernet0_2.id
depends_on = [azurerm_network_interface.ethernet0_2]
}
output "ingress_lb_pip" {
value = azurerm_public_ip.ingress.ip_address
}