-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmseries.tf
270 lines (230 loc) · 9.34 KB
/
vmseries.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
# Creation of the following resources:
# - Azure Public IPs (Management)
# Public IP Address:
resource "azurerm_public_ip" "management" {
for_each = var.vmseries
name = "${each.key}-nic-management-pip"
location = var.resource_location
resource_group_name = var.resource_group_name
allocation_method = "Static"
depends_on = [azurerm_resource_group.this]
sku = "Standard"
}
# Network Interface:
resource "azurerm_network_interface" "management" {
for_each = var.vmseries
name = "${each.key}-nic-management"
location = var.resource_location
resource_group_name = var.resource_group_name
enable_ip_forwarding = false
ip_configuration {
name = "ipconfig1"
subnet_id = azurerm_subnet.this["management"].id
private_ip_address_allocation = "Static"
private_ip_address = each.value.management_ip
public_ip_address_id = azurerm_public_ip.management[each.key].id
}
depends_on = [azurerm_resource_group.this]
}
resource "azurerm_network_security_group" "management" {
for_each = var.vmseries
name = "${each.key}-nsg-management"
location = var.resource_location
resource_group_name = var.resource_group_name
security_rule {
name = "management-inbound"
priority = 1000
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_ranges = ["443", "22"]
source_address_prefix = "0.0.0.0/0"
destination_address_prefix = "*"
}
depends_on = [azurerm_resource_group.this]
}
# Network Security Group (Management)
resource "azurerm_network_interface_security_group_association" "management" {
for_each = var.vmseries
network_interface_id = azurerm_network_interface.management[each.key].id
network_security_group_id = azurerm_network_security_group.management[each.key].id
}
#----------------------------------------------------------------------------------------------------------------------
# VM-Series - Ethernet0/1 Interface (Untrust)
#----------------------------------------------------------------------------------------------------------------------
# Public IP Address
resource "azurerm_public_ip" "ethernet_0_1" {
for_each = var.vmseries
name = "${each.key}-nic-ethernet01-pip"
location = var.resource_location
resource_group_name = var.resource_group_name
allocation_method = "Static"
depends_on = [azurerm_resource_group.this]
sku = "Standard"
}
# Network Interface
resource "azurerm_network_interface" "ethernet0_1" {
for_each = var.vmseries
name = "${each.key}-nic-ethernet01"
location = var.resource_location
resource_group_name = var.resource_group_name
enable_ip_forwarding = true
enable_accelerated_networking = true
ip_configuration {
name = "ipconfig1"
subnet_id = azurerm_subnet.this["public"].id
private_ip_address_allocation = "Static"
private_ip_address = each.value.public_ip
public_ip_address_id = azurerm_public_ip.ethernet_0_1[each.key].id
}
depends_on = [azurerm_resource_group.this]
}
resource "azurerm_network_security_group" "data" {
for_each = var.vmseries
name = "${each.key}-nsg-allow-all"
location = var.resource_location
resource_group_name = var.resource_group_name
security_rule {
name = "data-inbound"
priority = 1000
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "data-outbound"
priority = 1000
direction = "Outbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
}
depends_on = [azurerm_resource_group.this]
}
# Network Security Group (Data)
resource "azurerm_network_interface_security_group_association" "ethernet0_1" {
for_each = var.vmseries
network_interface_id = azurerm_network_interface.ethernet0_1[each.key].id
network_security_group_id = azurerm_network_security_group.data[each.key].id
}
#----------------------------------------------------------------------------------------------------------------------
# VM-Series - Ethernet0/2 Interface (Trust)
#----------------------------------------------------------------------------------------------------------------------
# Network Interface
resource "azurerm_network_interface" "ethernet0_2" {
for_each = var.vmseries
name = "${each.key}-nic-ethernet02"
location = var.resource_location
resource_group_name = var.resource_group_name
enable_ip_forwarding = true
enable_accelerated_networking = true
ip_configuration {
name = "ipconfig1"
subnet_id = azurerm_subnet.this["private"].id
private_ip_address_allocation = "Static"
private_ip_address = each.value.private_ip
}
depends_on = [azurerm_resource_group.this]
}
# Network Security Group (Data)
resource "azurerm_network_interface_security_group_association" "ethernet0_2" {
for_each = var.vmseries
network_interface_id = azurerm_network_interface.ethernet0_2[each.key].id
network_security_group_id = azurerm_network_security_group.data[each.key].id
}
#----------------------------------------------------------------------------------------------------------------------
# VM-Series - Ethernet0/2 Interface (Trust)
#----------------------------------------------------------------------------------------------------------------------
# Network Interface
resource "azurerm_network_interface" "ethernet0_3" {
for_each = var.vmseries
name = "${each.key}-nic-ethernet03"
location = var.resource_location
resource_group_name = var.resource_group_name
enable_ip_forwarding = true
enable_accelerated_networking = true
ip_configuration {
name = "ipconfig1"
subnet_id = azurerm_subnet.this["ha2"].id
private_ip_address_allocation = "Static"
private_ip_address = each.value.ha2_ip
}
depends_on = [azurerm_resource_group.this]
}
# Network Security Group (Data)
resource "azurerm_network_interface_security_group_association" "ethernet0_3" {
for_each = var.vmseries
network_interface_id = azurerm_network_interface.ethernet0_3[each.key].id
network_security_group_id = azurerm_network_security_group.data[each.key].id
}
#----------------------------------------------------------------------------------------------------------------------
# VM-Series - Virtual Machine
#----------------------------------------------------------------------------------------------------------------------
resource "azurerm_linux_virtual_machine" "vmseries" {
for_each = var.vmseries
# Resource Group & Location:
resource_group_name = var.resource_group_name
location = var.resource_location
name = "${each.key}-vm"
# Availabilty Zone:
zone = each.value.availability_zone
# Instance
size = each.value.instance_size
# Username and Password Authentication:
disable_password_authentication = false
admin_username = each.value.admin_username
admin_password = each.value.admin_password
# Network Interfaces:
network_interface_ids = [
azurerm_network_interface.management[each.key].id,
azurerm_network_interface.ethernet0_1[each.key].id,
azurerm_network_interface.ethernet0_2[each.key].id,
azurerm_network_interface.ethernet0_3[each.key].id,
]
plan {
name = each.value.license
publisher = "paloaltonetworks"
product = "vmseries-flex"
}
source_image_reference {
publisher = "paloaltonetworks"
offer = "vmseries-flex"
sku = each.value.license
version = each.value.version
}
os_disk {
name = "${each.key}-osdisk"
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
}
# Bootstrap Information for Azure:
custom_data = base64encode(join(
",",
[
"storage-account=${azurerm_storage_account.bootstrap.name}",
"access-key=${azurerm_storage_account.bootstrap.primary_access_key}",
"file-share=${azurerm_storage_share.bootstrap.name}",
"share-directory=${each.key}",
],
))
# Dependencies:
depends_on = [
azurerm_network_interface.ethernet0_2,
azurerm_network_interface.ethernet0_1,
azurerm_network_interface.management,
]
}
output "vmseries0_management_ip" {
value = azurerm_public_ip.management["vmseries0"].ip_address
}
output "vmseries1_management_ip" {
value = azurerm_public_ip.management["vmseries1"].ip_address
}