/
azfw.tf
171 lines (135 loc) · 4.77 KB
/
azfw.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
resource "azurerm_subnet" "snet-demo-test-westeurope-002" {
name = "AzureFirewallSubnet"
resource_group_name = azurerm_resource_group.rg-demo-test-westeurope-001.name
virtual_network_name = azurerm_virtual_network.vnet-demo-test-westeurope-001.name
address_prefixes = ["10.0.254.0/24"]
}
resource "azurerm_public_ip" "pip-demo-test-westeurope-001" {
name = "azfw-pip"
location = azurerm_resource_group.rg-demo-test-westeurope-001.location
resource_group_name = azurerm_resource_group.rg-demo-test-westeurope-001.name
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_firewall" "azfw-demo-test-westeurope-001" {
name = "azfw-demo-test-westeurope-001"
location = azurerm_resource_group.rg-demo-test-westeurope-001.location
resource_group_name = azurerm_resource_group.rg-demo-test-westeurope-001.name
ip_configuration {
name = "configuration"
subnet_id = azurerm_subnet.snet-demo-test-westeurope-002.id
public_ip_address_id = azurerm_public_ip.pip-demo-test-westeurope-001.id
}
}
resource "azurerm_firewall_network_rule_collection" "azfwnrc-demo-test-westeurope-001" {
name = "azfwnrc-demo-test-westeurope-001"
azure_firewall_name = azurerm_firewall.azfw-demo-test-westeurope-001.name
resource_group_name = azurerm_resource_group.rg-demo-test-westeurope-001.name
priority = 100
action = "Allow"
rule {
name = "allow outbound DNS"
source_addresses = [
"10.0.0.0/16",
]
destination_ports = [
"53",
]
destination_addresses = [
"8.8.8.8",
"8.8.4.4",
]
protocols = [
"TCP",
"UDP",
]
}
}
resource "azurerm_firewall_network_rule_collection" "azfwnrc-demo-test-westeurope-002" {
name = "azfwnrc-demo-test-westeurope-002"
azure_firewall_name = azurerm_firewall.azfw-demo-test-westeurope-001.name
resource_group_name = azurerm_resource_group.rg-demo-test-westeurope-001.name
priority = 110
action = "Allow"
rule {
name = "allow outbound www"
source_addresses = [
"10.0.0.0/16",
]
destination_ports = [
"80",
"443",
]
destination_addresses = [
"*",
]
protocols = [
"TCP",
]
}
}
resource "azurerm_firewall_nat_rule_collection" "natrc-demo-test-westeurope-001" {
name = "natrc-demo-test-westeurope-001"
azure_firewall_name = azurerm_firewall.azfw-demo-test-westeurope-001.name
resource_group_name = azurerm_resource_group.rg-demo-test-westeurope-001.name
priority = 100
action = "Dnat"
rule {
name = "allow inbound ssh"
source_addresses = [
var.mypublicip,
]
destination_ports = [
"22",
]
destination_addresses = [
azurerm_public_ip.pip-demo-test-westeurope-001.ip_address
]
translated_port = 22
translated_address = azurerm_network_interface.nic-demo-test-westeurope-001.private_ip_address
protocols = [
"TCP",
]
}
}
resource "azurerm_firewall_nat_rule_collection" "natrc-demo-test-westeurope-002" {
name = "natrc-demo-test-westeurope-002"
azure_firewall_name = azurerm_firewall.azfw-demo-test-westeurope-001.name
resource_group_name = azurerm_resource_group.rg-demo-test-westeurope-001.name
priority = 110
action = "Dnat"
rule {
name = "allow inbound web"
source_addresses = [
"*",
]
destination_ports = [
"80",
]
destination_addresses = [
azurerm_public_ip.pip-demo-test-westeurope-001.ip_address
]
translated_port = 80
translated_address = azurerm_network_interface.nic-demo-test-westeurope-001.private_ip_address
protocols = [
"TCP",
]
}
}
resource "azurerm_route_table" "rt-demo-test-westeurope-001" {
location = azurerm_resource_group.rg-demo-test-westeurope-001.location
name = "MyRouteTable"
resource_group_name = azurerm_resource_group.rg-demo-test-westeurope-001.name
}
resource "azurerm_route" "rou-demo-test-westeurope-001" {
name = "AzFirewallRoute"
resource_group_name = azurerm_resource_group.rg-demo-test-westeurope-001.name
route_table_name = azurerm_route_table.rt-demo-test-westeurope-001.name
address_prefix = "0.0.0.0/0"
next_hop_type = "virtualappliance"
next_hop_in_ip_address = azurerm_firewall.azfw-demo-test-westeurope-001.ip_configuration[0].private_ip_address
}
resource "azurerm_subnet_route_table_association" "rta-demo-test-westeurope-001" {
subnet_id = azurerm_subnet.snet-demo-test-westeurope-001.id
route_table_id = azurerm_route_table.rt-demo-test-westeurope-001.id
}