-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql-lb.tf
74 lines (66 loc) · 3.39 KB
/
sql-lb.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
#이 문서에서는 Azure Resource Manager로 실행 중인 단일 서브넷 내 Azure Virtual Machines에서 SQL Server Always On 가용성 그룹에 대한 부하 분산 장치를 만드는 방법을 설명합니다.
#SQL Server 인스턴스가 Azure Virtual Machines에 있는 경우 가용성 그룹을 사용하려면 부하 분산 장치가 필요합니다.
#Azure 가상 네트워크 내의 여러 서브넷에 만들면 AG(Always On 가용성 그룹)에 대한 Azure Load Balancer가 필요하지 않습니다.
#https://blog.pythian.com/sql-server-distributed-availability-group-with-forwarder-in-microsoft-azure/
#Create the SQL Load Balencer
resource "azurerm_lb" "sqlLB" {
name = "lb-sqlha"
location = azurerm_resource_group.ggResourcegroup.location
resource_group_name = azurerm_resource_group.ggResourcegroup.name
sku = "Standard"
frontend_ip_configuration {
name = "lb-sqlha-ip"
private_ip_address_allocation = "Static"
#private_ip_address = "${var.sqlServerConfig.sqlLBIPAddress}"
private_ip_address = "10.20.1.80" #10.20.1.64/26
subnet_id = azurerm_subnet.ggSubnet01.id
}
}
#Create the load balencer backend pool
resource "azurerm_lb_backend_address_pool" "sqlLBBEP" {
#resource_group_name = azurerm_resource_group.ggResourcegroup.name
loadbalancer_id = "${azurerm_lb.sqlLB.id}"
name = "sqlLB-bep"
}
#Add the VM to the load balencer
resource "azurerm_network_interface_backend_address_pool_association" "sqlvmBEAssoc" {
count = var.instances_num
network_interface_id = azurerm_network_interface.vm_nic[count.index].id
ip_configuration_name = "VM-sql${count.index}-IP"
backend_address_pool_id = azurerm_lb_backend_address_pool.sqlLBBEP.id
}
#Create the load balencer rules
resource "azurerm_lb_rule" "sqlLBRule" {
#resource_group_name = azurerm_resource_group.ggResourcegroup.name
loadbalancer_id = "${azurerm_lb.sqlLB.id}"
name = "lb-sqlha-lbrule"
protocol = "Tcp"
frontend_port = 1433
backend_port = 1433
frontend_ip_configuration_name = "lb-sqlha-ip"
probe_id = "${azurerm_lb_probe.sqlLBProbe.id}"
backend_address_pool_ids = [azurerm_lb_backend_address_pool.sqlLBBEP.id]
#enable_floating_ip = true
}
resource "azurerm_lb_rule" "sqlLBHAEndpointRule" {
#resource_group_name = azurerm_resource_group.ggResourcegroup.name
loadbalancer_id = "${azurerm_lb.sqlLB.id}"
name = "lb-sqlha-hadr-endpoint-lbrule"
protocol = "Tcp"
frontend_port = 5022
backend_port = 5022
frontend_ip_configuration_name = "lb-sqlha-ip"
probe_id = "${azurerm_lb_probe.sqlLBProbe.id}"
backend_address_pool_ids = [azurerm_lb_backend_address_pool.sqlLBBEP.id]
#enable_floating_ip = true
}
#Create a health probe for the load balencer
resource "azurerm_lb_probe" "sqlLBProbe" {
#resource_group_name = azurerm_resource_group.ggResourcegroup.name
loadbalancer_id = "${azurerm_lb.sqlLB.id}"
name = "lb-sqlha-SQLAOProbe"
port = 59999
protocol = "Tcp"
interval_in_seconds = 5
number_of_probes = 2
}