-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbigip.tf
313 lines (269 loc) · 11.9 KB
/
bigip.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# Create F5 BIGIP VMs
resource "azurerm_virtual_machine" "f5bigip" {
count = length(var.azs)
name = format("%s-bigip-%s-%s",var.prefix,count.index,random_id.randomId.hex)
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
primary_network_interface_id = azurerm_network_interface.mgmt-nic[count.index].id
network_interface_ids = [azurerm_network_interface.mgmt-nic[count.index].id, azurerm_network_interface.ext-nic[count.index].id,azurerm_network_interface.int-nic[count.index].id]
vm_size = var.instance_type
zones = [element(var.azs,count.index)]
# Uncomment this line to delete the OS disk automatically when deleting the VM
delete_os_disk_on_termination = true
# Uncomment this line to delete the data disks automatically when deleting the VM
delete_data_disks_on_termination = true
storage_image_reference {
publisher = "f5-networks"
offer = var.product[var.bigip_license == "" ? 0 : 1]
sku = var.image_name[var.bigip_license == "" ? 0 : 1]
version = var.bigip_version[var.bigip_license == "" ? 0 : 1]
}
storage_os_disk {
name = format("%s-bigip-osdisk-%s-%s",var.prefix,count.index,random_id.randomId.hex)
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
disk_size_gb = "80"
}
os_profile {
computer_name = format("%s-bigip-%s-%s",var.prefix,count.index,random_id.randomId.hex)
admin_username = "azureuser"
admin_password = random_password.password.result
custom_data = data.template_file.vm_onboard.rendered
}
os_profile_linux_config {
disable_password_authentication = false
}
plan {
name = var.image_name[var.bigip_license == "" ? 0 : 1]
publisher = "f5-networks"
product = var.product[var.bigip_license == "" ? 0 : 1]
}
tags = {
Name = format("%s-bigip-%s-%s",var.prefix,count.index,random_id.randomId.hex)
environment = "${var.environment}"
}
}
# Run Startup Script
resource "azurerm_virtual_machine_extension" "run_startup_cmd" {
count = length(var.azs)
name = format("%s-bigip-startup-%s-%s",var.prefix,count.index,random_id.randomId.hex)
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
virtual_machine_name = azurerm_virtual_machine.f5bigip[count.index].name
publisher = "Microsoft.OSTCExtensions"
type = "CustomScriptForLinux"
type_handler_version = "1.2"
settings = <<SETTINGS
{
"commandToExecute": "bash /var/lib/waagent/CustomData"
}
SETTINGS
tags = {
Name = format("%s-bigip-startup-%s-%s",var.prefix,count.index,random_id.randomId.hex)
environment = var.environment
}
}
# Create Network Security Group and rule
resource "azurerm_network_security_group" "management_sg" {
name = format("%s-mgmt_sg-%s",var.prefix,random_id.randomId.hex)
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
security_rule {
name = "SSH"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = var.allowed_mgmt_cidr
destination_address_prefix = "*"
}
security_rule {
name = "HTTPS"
priority = 1002
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "443"
source_address_prefix = var.allowed_mgmt_cidr
destination_address_prefix = "*"
}
security_rule {
name = "SSH-internal"
priority = 1003
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = var.cidr
destination_address_prefix = "*"
}
security_rule {
name = "HTTPS-internal"
priority = 1004
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "443"
source_address_prefix = var.cidr
destination_address_prefix = "*"
}
tags = {
environment = var.environment
}
}
# Create interfaces for the BIGIPs
resource "azurerm_network_interface" "mgmt-nic" {
count = length(var.azs)
name = format("%s-mgmtnic-%s-%s",var.prefix,count.index,random_id.randomId.hex)
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
network_security_group_id = azurerm_network_security_group.management_sg.id
ip_configuration {
name = "primary"
subnet_id = azurerm_subnet.management[count.index].id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.management_public_ip[count.index].id
}
tags = {
Name = format("%s-mgmtnic-%s-%s",var.prefix,count.index,random_id.randomId.hex)
environment = var.environment
}
}
# Create Application Traffic Network Security Group and rule
resource "azurerm_network_security_group" "application_sg" {
name = format("%s-application_sg-%s",var.prefix,random_id.randomId.hex)
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
security_rule {
name = "HTTPS"
priority = 1002
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "443"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "HTTP"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"
}
tags = {
environment = var.environment
}
}
resource "azurerm_network_interface" "ext-nic" {
count = length(var.azs)
name = format("%s-extnic-%s-%s",var.prefix,count.index,random_id.randomId.hex)
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
network_security_group_id = azurerm_network_security_group.application_sg.id
enable_ip_forwarding = true
ip_configuration {
name = "primary"
subnet_id = azurerm_subnet.public[count.index].id
private_ip_address_allocation = "Dynamic"
primary = true
}
ip_configuration {
name = "juiceshop"
subnet_id = azurerm_subnet.public[count.index].id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.juiceshop_public_ip[count.index].id
}
ip_configuration {
name = "grafana"
subnet_id = azurerm_subnet.public[count.index].id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.grafana_public_ip[count.index].id
}
tags = {
Name = format("%s-extnic-%s-%s",var.prefix,count.index,random_id.randomId.hex)
environment = var.environment
}
}
resource "azurerm_network_interface" "int-nic" {
count = length(var.azs)
name = format("%s-intnic-%s-%s",var.prefix,count.index,random_id.randomId.hex)
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
network_security_group_id = azurerm_network_security_group.management_sg.id
enable_ip_forwarding = true
ip_configuration {
name = "primary"
subnet_id = azurerm_subnet.private[count.index].id
private_ip_address_allocation = "Dynamic"
primary = true
}
tags = {
Name = format("%s-intnic-%s-%s",var.prefix,count.index,random_id.randomId.hex)
environment = var.environment
}
}
# Create public IPs for BIG-IP management UI
resource "azurerm_public_ip" "management_public_ip" {
count = length(var.azs)
name = format("%s-bigip-%s-%s",var.prefix,count.index,random_id.randomId.hex)
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
allocation_method = "Static" # Static is required due to the use of the Standard sku
sku = "Standard" # the Standard sku is required due to the use of availability zones
zones = [element(var.azs,count.index)]
tags = {
environment = var.environment
}
}
# Create public IPs for JuiceShop
resource "azurerm_public_ip" "juiceshop_public_ip" {
count = length(var.azs)
name = format("%s-juiceshop-%s-%s",var.prefix,count.index,random_id.randomId.hex)
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
allocation_method = "Static" # Static is required due to the use of the Standard sku
sku = "Standard" # the Standard sku is required due to the use of availability zones
zones = [element(var.azs,count.index)]
tags = {
environment = var.environment
}
}
# Create public IPs for Grafana
resource "azurerm_public_ip" "grafana_public_ip" {
count = length(var.azs)
name = format("%s-grafana-%s-%s",var.prefix,count.index,random_id.randomId.hex)
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
allocation_method = "Static" # Static is required due to the use of the Standard sku
sku = "Standard" # the Standard sku is required due to the use of availability zones
zones = [element(var.azs,count.index)]
tags = {
environment = var.environment
}
}
# Setup Onboarding scripts
data "template_file" "vm_onboard" {
template = "${file("${path.module}/onboard.tpl")}"
vars = {
uname = var.admin_username
# replace this with a reference to the secret id
upassword = random_password.password.result
DO_URL = var.DO_URL
AS3_URL = var.AS3_URL
TS_URL = var.TS_URL
libs_dir = var.libs_dir
onboard_log = var.onboard_log
}
}