-
Notifications
You must be signed in to change notification settings - Fork 1
/
bwaf-playground.tf
300 lines (249 loc) · 8.76 KB
/
bwaf-playground.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
# Configure the Azure Provider
provider "azurerm" {
# whilst the `version` attribute is optional, we recommend pinning to a given version of the Provider
version = "=1.43.0"
}
# Gather resource group name
variable "rg_name" {
type = string
description = "Enter the resource group to create resources in. For SEs at Barracuda Networks, this is typically Firstname_Lastname (e.g. John_Smith) "
}
# Gather location
variable "rg_location" {
type = string
description = "Enter your location (e.g. eastus) "
}
# Create the resource group
resource "azurerm_resource_group" "rg_playground" {
name = var.rg_name
location = var.rg_location
tags = {
environment = "Terraform BWAF"
}
}
# Create virtual network
resource "azurerm_virtual_network" "network_playground" {
name = "network_playground"
address_space = ["10.0.0.0/16"]
location = "eastus"
resource_group_name = azurerm_resource_group.rg_playground.name
tags = {
environment = "Terraform BWAF"
}
}
# Create subnet
resource "azurerm_subnet" "subnet_playground" {
name = "subnet_playground"
resource_group_name = azurerm_resource_group.rg_playground.name
virtual_network_name = azurerm_virtual_network.network_playground.name
address_prefix = "10.0.1.0/24"
}
# Create public IPs
resource "azurerm_public_ip" "public_ip_ubuntu" {
name = "public_ip_ubuntu"
location = "eastus"
resource_group_name = azurerm_resource_group.rg_playground.name
allocation_method = "Dynamic"
tags = {
environment = "Terraform BWAF"
}
}
resource "azurerm_public_ip" "public_ip_bwaf" {
name = "public_ip_bwaf"
location = "eastus"
resource_group_name = azurerm_resource_group.rg_playground.name
allocation_method = "Dynamic"
tags = {
environment = "Terraform BWAF"
}
}
# Create Network Security Group and rule
resource "azurerm_network_security_group" "nsg_playground" {
name = "nsg_playground"
location = "eastus"
resource_group_name = azurerm_resource_group.rg_playground.name
security_rule {
name = "SSH"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "80"
priority = 1002
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "8080"
priority = 1003
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "8080"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "8K"
priority = 1004
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "8000"
source_address_prefix = "*"
destination_address_prefix = "*"
}
tags = {
environment = "Terraform BWAF"
}
}
# Create network interface
resource "azurerm_network_interface" "nic_bwaf" {
name = "nic_bwaf"
location = "eastus"
resource_group_name = azurerm_resource_group.rg_playground.name
network_security_group_id = azurerm_network_security_group.nsg_playground.id
ip_configuration {
name = "nic_cfg_bwaf"
subnet_id = azurerm_subnet.subnet_playground.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.public_ip_bwaf.id
}
tags = {
environment = "Terraform BWAF"
}
}
# Create network interface
resource "azurerm_network_interface" "nic_ubuntu" {
name = "nic_ubuntu"
location = "eastus"
resource_group_name = azurerm_resource_group.rg_playground.name
network_security_group_id = azurerm_network_security_group.nsg_playground.id
ip_configuration {
name = "nic_cfg_ubuntu"
subnet_id = azurerm_subnet.subnet_playground.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.public_ip_ubuntu.id
}
tags = {
environment = "Terraform BWAF"
}
}
# Generate random text for a unique storage account name
resource "random_id" "randomId" {
keepers = {
# Generate a new ID only when a new resource group is defined
resource_group = azurerm_resource_group.rg_playground.name
}
byte_length = 8
}
# Create storage account for boot diagnostics
resource "azurerm_storage_account" "sa_ubuntu" {
name = "diag${random_id.randomId.hex}"
resource_group_name = azurerm_resource_group.rg_playground.name
location = "eastus"
account_tier = "Standard"
account_replication_type = "LRS"
tags = {
environment = "Terraform BWAF"
}
}
data "azurerm_public_ip" "public_ip_bwaf" {
name = "${azurerm_public_ip.public_ip_bwaf.name}"
resource_group_name = var.rg_name
}
output "public_ip_address" {
value = "${data.azurerm_public_ip.public_ip_bwaf.ip_address}"
}
#create bwaf
resource "azurerm_virtual_machine" "vm_bwaf" {
name = "vm_bwaf"
location = "eastus"
plan {
publisher = "barracudanetworks"
name = "hourly"
product = "waf"
}
resource_group_name = azurerm_resource_group.rg_playground.name
network_interface_ids = [azurerm_network_interface.nic_bwaf.id]
vm_size = "Standard_DS1_v2"
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true
storage_os_disk {
name = "osdisk_bwaf"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
storage_image_reference {
publisher = "barracudanetworks"
offer = "waf"
sku = "hourly"
version = "latest"
}
os_profile {
computer_name = "vm-bwaf"
admin_username = "not_used"
admin_password = "Hello123456!"
custom_data = "{\"signature\": \"WaaS_Support\", \"email\": \"[email protected]\", \"organization\": \"Barracuda Networks, Inc.\"}"
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = {
environment = "Terraform BWAF"
}
}
# Create virtual machine
resource "azurerm_virtual_machine" "vm_ubuntu" {
name = "vm_ubuntu"
location = "eastus"
resource_group_name = azurerm_resource_group.rg_playground.name
network_interface_ids = [azurerm_network_interface.nic_ubuntu.id]
vm_size = "Standard_DS1_v2"
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true
storage_os_disk {
name = "osdisk_ubuntu"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04.0-LTS"
version = "latest"
}
os_profile {
computer_name = "vm-ubuntu"
admin_username = "azureuser"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/azureuser/.ssh/authorized_keys"
key_data = "${file("~/.ssh/id_rsa.pub")}"
}
}
boot_diagnostics {
enabled = "true"
storage_uri = azurerm_storage_account.sa_ubuntu.primary_blob_endpoint
}
tags = {
environment = "Terraform BWAF"
}
}