-
Notifications
You must be signed in to change notification settings - Fork 138
/
main.tf
177 lines (150 loc) · 5.17 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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
data "azurerm_resource_group" "hub" {
name = var.resource_group_name
}
data "azurerm_virtual_network" "hub" {
name = var.vnet_name
resource_group_name = data.azurerm_resource_group.hub.name
}
data "azurerm_subnet" "fw_client_sn" {
name = var.firewall_client_subnet_name
virtual_network_name = data.azurerm_virtual_network.hub.name
resource_group_name = data.azurerm_resource_group.hub.name
}
data "azurerm_subnet" "fw_mgmt_sn" {
name = var.firewall_management_subnet_name
virtual_network_name = data.azurerm_virtual_network.hub.name
resource_group_name = data.azurerm_resource_group.hub.name
}
resource "azurerm_public_ip" "fw_client_pip" {
name = var.client_publicip_name
location = var.location
resource_group_name = data.azurerm_resource_group.hub.name
allocation_method = "Static"
sku = "Standard"
availability_zone = "No-Zone"
tags = var.tags
}
resource "azurerm_public_ip" "fw_mgmt_pip" {
name = var.management_publicip_name
location = var.location
resource_group_name = data.azurerm_resource_group.hub.name
allocation_method = "Static"
sku = "Standard"
availability_zone = "No-Zone"
tags = var.tags
}
resource "azurerm_firewall_policy" "firewallpolicy" {
name = var.firewall_policy_name
resource_group_name = data.azurerm_resource_group.hub.name
location = var.location
sku = var.firewall_sku
threat_intelligence_mode = "Alert"
}
resource "azurerm_firewall" "firewall" {
name = var.firewall_name
location = var.location
resource_group_name = data.azurerm_resource_group.hub.name
sku_tier = var.firewall_sku
private_ip_ranges = var.disable_snat_ip_range
firewall_policy_id = azurerm_firewall_policy.firewallpolicy.id
tags = var.tags
dns_servers = null
zones = null
ip_configuration {
name = var.client_ipconfig_name
subnet_id = "/subscriptions/${var.sub_id}/resourceGroups/${var.resource_group_name}/providers/Microsoft.Network/virtualNetworks/${var.vnet_name}/subnets/AzureFirewallSubnet"
public_ip_address_id = azurerm_public_ip.fw_client_pip.id
}
management_ip_configuration {
name = var.management_ipconfig_name
subnet_id = "/subscriptions/${var.sub_id}/resourceGroups/${var.resource_group_name}/providers/Microsoft.Network/virtualNetworks/${var.vnet_name}/subnets/AzureFirewallManagementSubnet"
public_ip_address_id = azurerm_public_ip.fw_mgmt_pip.id
}
}
resource "random_id" "storageaccount" {
byte_length = 12
}
resource "azurerm_storage_account" "loganalytics" {
name = format("%.24s", lower(replace("${azurerm_firewall.firewall.name}logs${random_id.storageaccount.id}", "/[[:^alnum:]]/", "")))
resource_group_name = data.azurerm_resource_group.hub.name
location = var.location
account_kind = "StorageV2"
account_tier = "Standard"
account_replication_type = "LRS"
enable_https_traffic_only = true
tags = var.tags
}
resource "azurerm_monitor_diagnostic_setting" "firewall-diagnostics" {
name = "${azurerm_firewall.firewall.name}-fw-diagnostics"
target_resource_id = "/subscriptions/${var.sub_id}/resourceGroups/${var.resource_group_name}/providers/Microsoft.Network/azureFirewalls/${var.firewall_name}"
storage_account_id = azurerm_storage_account.loganalytics.id
log_analytics_workspace_id = var.log_analytics_workspace_resource_id
log {
category = "AzureFirewallApplicationRule"
enabled = true
retention_policy {
days = 30
enabled = true
}
}
log {
category = "AzureFirewallNetworkRule"
enabled = true
retention_policy {
days = 30
enabled = true
}
}
log {
category = "AzureFirewallDnsProxy"
enabled = true
retention_policy {
days = 30
enabled = true
}
}
metric {
category = "AllMetrics"
retention_policy {
enabled = false
}
}
}
resource "azurerm_monitor_diagnostic_setting" "publicip-diagnostics" {
name = "${azurerm_public_ip.fw_client_pip.name}-pip-diagnostics"
target_resource_id = azurerm_public_ip.fw_client_pip.id
storage_account_id = azurerm_storage_account.loganalytics.id
log_analytics_workspace_id = var.log_analytics_workspace_resource_id
log {
category = "DDoSProtectionNotifications"
enabled = true
retention_policy {
days = 30
enabled = true
}
}
log {
category = "DDoSMitigationFlowLogs"
enabled = true
retention_policy {
days = 30
enabled = true
}
}
log {
category = "DDoSMitigationReports"
enabled = true
retention_policy {
days = 30
enabled = true
}
}
metric {
category = "AllMetrics"
retention_policy {
enabled = false
}
}
}