-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathmain.tf
128 lines (113 loc) · 5.86 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
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
# Azure load balancer module
data "azurerm_resource_group" "azlb" {
name = var.resource_group_name
}
data "azurerm_subnet" "snet" {
count = (var.frontend_subnet_name != null && var.frontend_subnet_name != "") ? 1 : 0
name = var.frontend_subnet_name
resource_group_name = data.azurerm_resource_group.azlb.name
virtual_network_name = var.frontend_vnet_name
}
locals {
data_subnet_id = try(data.azurerm_subnet.snet[0].id, "")
}
resource "azurerm_public_ip" "azlb" {
count = var.type == "public" ? 1 : 0
allocation_method = var.allocation_method
location = coalesce(var.location, data.azurerm_resource_group.azlb.location)
name = local.pip_name
resource_group_name = data.azurerm_resource_group.azlb.name
ddos_protection_mode = var.pip_ddos_protection_mode
ddos_protection_plan_id = var.pip_ddos_protection_plan_id
domain_name_label = var.pip_domain_name_label
edge_zone = var.edge_zone
idle_timeout_in_minutes = var.pip_idle_timeout_in_minutes
ip_tags = var.pip_ip_tags
ip_version = var.pip_ip_version
public_ip_prefix_id = var.pip_public_ip_prefix_id
reverse_fqdn = var.pip_reverse_fqdn
sku = var.pip_sku
sku_tier = var.pip_sku_tier
tags = merge(var.tags, (/*<box>*/ (var.tracing_tags_enabled ? { for k, v in /*</box>*/ {
avm_git_commit = "d8466522dbee909d833e8f6c51c4c7ec587496d5"
avm_git_file = "main.tf"
avm_git_last_modified_at = "2023-01-16 05:50:14"
avm_git_org = "Azure"
avm_git_repo = "terraform-azurerm-loadbalancer"
avm_yor_trace = "03590a88-0f94-4050-af13-c3cc444f3165"
} /*<box>*/ : replace(k, "avm_", var.tracing_tags_prefix) => v } : {}) /*</box>*/), (/*<box>*/ (var.tracing_tags_enabled ? { for k, v in /*</box>*/ {
avm_yor_name = "azlb"
} /*<box>*/ : replace(k, "avm_", var.tracing_tags_prefix) => v } : {}) /*</box>*/))
zones = var.pip_zones
}
resource "azurerm_lb" "azlb" {
location = coalesce(var.location, data.azurerm_resource_group.azlb.location)
name = local.lb_name
resource_group_name = data.azurerm_resource_group.azlb.name
edge_zone = var.edge_zone
sku = var.lb_sku
sku_tier = var.lb_sku_tier
tags = merge(var.tags, (/*<box>*/ (var.tracing_tags_enabled ? { for k, v in /*</box>*/ {
avm_git_commit = "3b4dfbcc5c5c3ffe20327f21ab16ef2464ed94aa"
avm_git_file = "main.tf"
avm_git_last_modified_at = "2023-01-31 02:40:02"
avm_git_org = "Azure"
avm_git_repo = "terraform-azurerm-loadbalancer"
avm_yor_trace = "94f04f8b-b6ac-42d4-8e4a-b564ea9657ab"
} /*<box>*/ : replace(k, "avm_", var.tracing_tags_prefix) => v } : {}) /*</box>*/), (/*<box>*/ (var.tracing_tags_enabled ? { for k, v in /*</box>*/ {
avm_yor_name = "azlb"
} /*<box>*/ : replace(k, "avm_", var.tracing_tags_prefix) => v } : {}) /*</box>*/))
frontend_ip_configuration {
name = var.frontend_name
private_ip_address = var.frontend_private_ip_address
private_ip_address_allocation = var.frontend_private_ip_address_allocation
private_ip_address_version = var.frontend_private_ip_address_version
public_ip_address_id = try(azurerm_public_ip.azlb[0].id, null)
subnet_id = local.subnet_id
zones = var.frontend_ip_zones
}
lifecycle {
precondition {
condition = var.frontend_subnet_name == null || var.frontend_subnet_name == "" || var.frontend_subnet_id == null || var.frontend_subnet_id == ""
error_message = "frontend_subnet_name or frontend_vent_name cannot exist if frontend_subnet_id exists."
}
}
}
resource "azurerm_lb_backend_address_pool" "azlb" {
loadbalancer_id = azurerm_lb.azlb.id
name = "BackEndAddressPool"
}
resource "azurerm_lb_nat_rule" "azlb" {
count = length(var.remote_port)
backend_port = element(var.remote_port[element(keys(var.remote_port), count.index)], 1)
frontend_ip_configuration_name = var.frontend_name
loadbalancer_id = azurerm_lb.azlb.id
name = "VM-${count.index}"
protocol = "Tcp"
resource_group_name = data.azurerm_resource_group.azlb.name
frontend_port = "5000${count.index + 1}"
}
resource "azurerm_lb_probe" "azlb" {
count = length(var.lb_probe)
loadbalancer_id = azurerm_lb.azlb.id
name = element(keys(var.lb_probe), count.index)
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
protocol = element(var.lb_probe[element(keys(var.lb_probe), count.index)], 0)
request_path = element(var.lb_probe[element(keys(var.lb_probe), count.index)], 2)
}
resource "azurerm_lb_rule" "azlb" {
count = length(var.lb_port)
backend_port = element(var.lb_port[element(keys(var.lb_port), count.index)], 2)
frontend_ip_configuration_name = var.frontend_name
frontend_port = element(var.lb_port[element(keys(var.lb_port), count.index)], 0)
loadbalancer_id = azurerm_lb.azlb.id
name = element(keys(var.lb_port), count.index)
protocol = element(var.lb_port[element(keys(var.lb_port), count.index)], 1)
backend_address_pool_ids = [azurerm_lb_backend_address_pool.azlb.id]
disable_outbound_snat = var.disable_outbound_snat
enable_floating_ip = var.lb_floating_ip_enabled
idle_timeout_in_minutes = 5
probe_id = element(azurerm_lb_probe.azlb[*].id, count.index)
}