-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.tf
260 lines (223 loc) · 8.66 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
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
provider "azurerm" {
# The "feature" block is required for AzureRM provider 2.x.
# If you are using version 1.x, the "features" block is not allowed.
version = "~>2.0"
features {}
}
###########################
# Resource group for all network related resources
###########################
resource "azurerm_resource_group" "vnet" {
name = join("", list(var.prefix, "-rg"))
location = var.location
}
###########################
# Create VNET
###########################
resource "azurerm_virtual_network" "vnet" {
name = join("", list(var.prefix, "-vnet"))
address_space = [ join("", list(var.IPAddressPrefix, ".0.0/16")) ]
location = azurerm_resource_group.vnet.location
resource_group_name = azurerm_resource_group.vnet.name
# dns_servers = [ "10.54.0.100","10.51.255.164"]
}
###########################
# Define subnets
###########################
# PAN mgmt interface
resource "azurerm_subnet" "fwmgmt" {
name = "fwmgmt"
resource_group_name = azurerm_resource_group.vnet.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = [ join("", list(var.IPAddressPrefix, ".1.0/24")) ]
}
# PAN FW outside
resource "azurerm_subnet" "fwuntrust" {
name = "fwuntrust"
resource_group_name = azurerm_resource_group.vnet.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = [ join("", list(var.IPAddressPrefix, ".2.0/24")) ]
}
# PAN FW inside
resource "azurerm_subnet" "fwtrust" {
name = "fwtrust"
resource_group_name = azurerm_resource_group.vnet.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = [ join("", list(var.IPAddressPrefix, ".3.0/24")) ]
}
# private server subnet
# All Internet outbound traffic will be routed to the PAN FW
resource "azurerm_subnet" "private" {
name = "private"
resource_group_name = azurerm_resource_group.vnet.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = [ join("", list(var.IPAddressPrefix, ".4.0/24")) ]
# Add Azure service endpoints needed in this subnet
service_endpoints = [ "Microsoft.Storage" ]
}
# Will be configured with a route table that does not use the PAN FW
# For VMs directly accessed from the Internet
resource "azurerm_subnet" "public" {
name = "public"
resource_group_name = azurerm_resource_group.vnet.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = [ join("", list(var.IPAddressPrefix, ".5.0/24")) ]
# Add Azure service endpoints needed in this subnet
service_endpoints = [ "Microsoft.Storage" ]
}
# Workstations subnet
# All Internet outbound traffic will be routed to the PAN FW
resource "azurerm_subnet" "vdesktop" {
name = "vdesktop"
resource_group_name = azurerm_resource_group.vnet.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = [ join("", list(var.IPAddressPrefix, ".6.0/24")) ]
# Add Azure service endpoints needed in this subnet
service_endpoints = [ "Microsoft.Storage" ]
}
# Required by Azure Basiton service
resource "azurerm_subnet" "bastion" {
name = "AzureBastionSubnet"
resource_group_name = azurerm_resource_group.vnet.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = [ join("", list(var.IPAddressPrefix, ".7.0/24")) ]
}
###########################
# Create bastion service
###########################
# Create a public IP address for the bastion service
resource "azurerm_public_ip" "bastion" {
name = join("", list(var.prefix, "-bastion"))
resource_group_name = azurerm_resource_group.vnet.name
location = azurerm_resource_group.vnet.location
allocation_method = "Static"
sku = "Standard"
domain_name_label = join("", list("scb", substr(md5(azurerm_resource_group.vnet.id), 0, 4)))
}
# Create the bastion service
resource "azurerm_bastion_host" "bastion" {
name = join("", list(var.prefix, "-bastion"))
resource_group_name = azurerm_resource_group.vnet.name
location = azurerm_resource_group.vnet.location
ip_configuration {
name = "configuration"
subnet_id = azurerm_subnet.bastion.id
public_ip_address_id = azurerm_public_ip.bastion.id
}
}
###########################
# Create route table and bind to required to subnets
###########################
# This table sends all non-vnet local traffic to the PAN firewall
resource "azurerm_route_table" "pan_fw1" {
name = join("", list(var.prefix, "-panfw"))
location = azurerm_resource_group.vnet.location
resource_group_name = azurerm_resource_group.vnet.name
disable_bgp_route_propagation = false
route {
name = "to-inet-pan"
address_prefix = "0.0.0.0/0"
next_hop_type = "VirtualAppliance"
# Nexthop is the PAN virtual appliance VNIC2 aka the trust interface
next_hop_in_ip_address = azurerm_network_interface.FW_VNIC2.private_ip_address
}
}
# Bind route table to subnets
# In only the VDI and server subnet will be forced to route Internet traffic to the PAN
resource "azurerm_subnet_route_table_association" "server_fw1_map" {
subnet_id = azurerm_subnet.private.id
route_table_id = azurerm_route_table.pan_fw1.id
}
resource "azurerm_subnet_route_table_association" "vdesktop_fw1_map" {
subnet_id = azurerm_subnet.vdesktop.id
route_table_id = azurerm_route_table.pan_fw1.id
}
###########################
# NSG For public subnet
###########################
resource "azurerm_network_security_group" "public" {
name = join("", list(var.prefix, "-publicdmz"))
location = azurerm_resource_group.vnet.location
resource_group_name = azurerm_resource_group.vnet.name
# Allow traffic from the Internet to port 443
security_rule {
name = "Allow-Internet"
priority = 500
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "443"
source_address_prefix = "*"
destination_address_prefix = "*"
}
# Restrict access to the rest of the subnets in the VNET
security_rule {
name = "Block-VNET"
priority = 1000
direction = "Outbound"
access = "Deny"
protocol = "*"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = join("", list(var.IPAddressPrefix, ".0.0/16"))
}
}
# Associated the NSG with publicdmz subnet
resource "azurerm_subnet_network_security_group_association" "public" {
subnet_id = azurerm_subnet.public.id
network_security_group_id = azurerm_network_security_group.public.id
}
###########################
# Testing desktop
# Uncomment if you want test machine ready
# Use bastion service to connect to it
# Don't forget to change the admin password below
###########################
/*
resource "azurerm_network_interface" "vdi0" {
name = "example-vdi0"
location = azurerm_resource_group.vnet.location
resource_group_name = azurerm_resource_group.vnet.name
ip_configuration {
name = "ipconfig0"
subnet_id = azurerm_subnet.vdesktop.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_virtual_machine" "vdi0" {
name = "example-vdi0"
location = azurerm_resource_group.vnet.location
resource_group_name = azurerm_resource_group.vnet.name
network_interface_ids = [azurerm_network_interface.vdi0.id]
vm_size = "Standard_B1ms"
delete_os_disk_on_termination = true
depends_on = [azurerm_virtual_machine.PAN_FW_FW]
storage_image_reference {
publisher = "MicrosoftWindowsDesktop"
offer = "Windows-10"
sku = "rs5-pro"
version = "latest"
}
storage_os_disk {
name = "example-vdi0_osdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "example-vdi0"
admin_username = "adminzzz"
admin_password = "!!!CHANGE ME!!!"
}
os_profile_windows_config {
enable_automatic_upgrades = true
provision_vm_agent = true
}
boot_diagnostics {
enabled = true
storage_uri = azurerm_storage_account.workstation.primary_blob_endpoint
}
}
*/