-
Notifications
You must be signed in to change notification settings - Fork 0
/
nva.tf
211 lines (178 loc) · 7.42 KB
/
nva.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
locals {
nva = {
name_prefix = var.name_prefix
resource_group_name = var.resource_group_name
location = var.location
vnet_prefix = var.vnet_prefix
subnets = cidrsubnets(var.vnet_prefix, 2, 2, 2, 2)
bgp_asn = var.nva_bgp_asn
type = var.nva_type
}
}
resource "azurerm_resource_group" "rsg" {
name = local.nva.resource_group_name
location = local.nva.location
}
resource "azurerm_virtual_network" "transit" {
name = "${local.nva.name_prefix}-transit-vnet"
address_space = [local.nva.vnet_prefix]
location = azurerm_resource_group.rsg.location
resource_group_name = azurerm_resource_group.rsg.name
}
resource "azurerm_subnet" "transit_external" {
name = "${local.nva.name_prefix}-transit-snet-external"
resource_group_name = azurerm_resource_group.rsg.name
virtual_network_name = azurerm_virtual_network.transit.name
address_prefixes = [local.nva.subnets[1]]
}
resource "azurerm_subnet" "transit_internal" {
name = "${local.nva.name_prefix}-transit-snet-internal"
resource_group_name = azurerm_resource_group.rsg.name
virtual_network_name = azurerm_virtual_network.transit.name
address_prefixes = [local.nva.subnets[0]]
}
resource "azurerm_public_ip" "nva_pip" {
count = 2
name = "${local.nva.name_prefix}-${count.index}-nva-pip"
resource_group_name = azurerm_resource_group.rsg.name
location = azurerm_resource_group.rsg.location
allocation_method = "Static"
sku = "Standard"
zones = var.availability_zone_support == true ? [1, 2, 3] : null
ip_tags = var.availability_zone_support == true ? {
RoutingPreference = "Internet"
} : null
}
resource "azurerm_availability_set" "nva_availability_set" {
count = var.availability_zone_support == false ? 1 : 0
name = "${local.nva.name_prefix}-nva-avail"
location = azurerm_resource_group.rsg.location
resource_group_name = azurerm_resource_group.rsg.name
platform_fault_domain_count = 2
}
resource "azurerm_network_interface" "nva_vm_internal" {
count = 2
name = "${local.nva.name_prefix}-${count.index}-internal-nic"
resource_group_name = azurerm_resource_group.rsg.name
location = azurerm_resource_group.rsg.location
enable_ip_forwarding = true
enable_accelerated_networking = true
ip_configuration {
name = "${local.nva.name_prefix}-${count.index}-internal-ip"
subnet_id = azurerm_subnet.transit_internal.id
private_ip_address_allocation = "Dynamic"
}
}
# swap the ips for l3 ha sync
locals {
nva_ha_peer_ip = [
azurerm_network_interface.nva_vm_internal[1].private_ip_address,
azurerm_network_interface.nva_vm_internal[0].private_ip_address
]
}
resource "azurerm_network_interface" "nva_vm_external" {
count = 2
name = "${local.nva.name_prefix}-${count.index}-external-nic"
resource_group_name = azurerm_resource_group.rsg.name
location = azurerm_resource_group.rsg.location
enable_ip_forwarding = true
enable_accelerated_networking = true
ip_configuration {
name = "${local.nva.name_prefix}-${count.index}-external-ip"
subnet_id = azurerm_subnet.transit_external.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.nva_pip[count.index].id
}
}
resource "azurerm_network_security_group" "nva_nsg_external" {
name = "${local.nva.name_prefix}-nsg-external"
location = azurerm_resource_group.rsg.location
resource_group_name = azurerm_resource_group.rsg.name
dynamic "security_rule" {
for_each = var.trusted_hosts
content {
access = "Allow"
direction = "Inbound"
name = security_rule.value.name
priority = security_rule.value.priority
protocol = "*"
source_port_range = "*"
source_address_prefix = security_rule.value.prefix
destination_port_range = "*"
destination_address_prefix = "*"
}
}
security_rule {
access = "Deny"
direction = "Inbound"
name = "denymgmt"
priority = 250
protocol = "*"
source_port_range = "*"
source_address_prefix = "0.0.0.0/0"
destination_port_range = "10443"
destination_address_prefix = "*"
}
security_rule {
access = "Allow"
direction = "Inbound"
name = "vpn"
priority = 4000
protocol = "*"
source_port_range = "*"
source_address_prefix = "0.0.0.0/0"
destination_port_range = "*"
destination_address_prefix = "*"
}
}
resource "azurerm_network_interface_security_group_association" "nva_external" {
count = 2
network_interface_id = azurerm_network_interface.nva_vm_external[count.index].id
network_security_group_id = azurerm_network_security_group.nva_nsg_external.id
}
resource "azurerm_lb" "ilb" {
count = var.use_ilb == true ? 1 : 0
name = "${local.nva.name_prefix}-nva-ilb"
location = azurerm_resource_group.rsg.location
resource_group_name = azurerm_resource_group.rsg.name
sku = "Standard"
frontend_ip_configuration {
name = "${local.nva.name_prefix}-nva-ilb-frontend"
zones = var.availability_zone_support == true ? [1, 2, 3] : null
subnet_id = azurerm_subnet.transit_internal.id
private_ip_address_allocation = "Dynamic"
private_ip_address_version = "IPv4"
}
}
resource "azurerm_lb_backend_address_pool" "ilb_backend" {
count = var.use_ilb ? 1 : 0
loadbalancer_id = azurerm_lb.ilb[0].id
name = "${local.nva.name_prefix}-nva-ilb-backend"
}
resource "azurerm_network_interface_backend_address_pool_association" "nvailb_backendpool" {
count = var.use_ilb ? 2 : 0
network_interface_id = azurerm_network_interface.nva_vm_internal[count.index].id
ip_configuration_name = azurerm_network_interface.nva_vm_internal[count.index].ip_configuration[0].name
backend_address_pool_id = azurerm_lb_backend_address_pool.ilb_backend[0].id
}
resource "azurerm_lb_probe" "nva_ilb_probe" {
count = var.use_ilb ? 1 : 0
loadbalancer_id = azurerm_lb.ilb[0].id
name = "ilb-nva-probe"
port = 8008
interval_in_seconds = 5
}
resource "azurerm_lb_rule" "nva_ilb_ha" {
count = var.use_ilb ? 1 : 0
loadbalancer_id = azurerm_lb.ilb[0].id
name = "NVA-HA"
frontend_ip_configuration_name = azurerm_lb.ilb[0].frontend_ip_configuration[0].name
protocol = "All"
idle_timeout_in_minutes = 30
probe_id = azurerm_lb_probe.nva_ilb_probe[0].id
backend_address_pool_ids = [azurerm_lb_backend_address_pool.ilb_backend[0].id]
enable_floating_ip = true
load_distribution = "Default"
frontend_port = 0
backend_port = 0
}