Skip to content

Commit a5adfe3

Browse files
authored
Fix: Bug Fixes (#53)
1 parent b13fa1b commit a5adfe3

File tree

8 files changed

+199
-77
lines changed

8 files changed

+199
-77
lines changed

README.md

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module "hubnetworks" {
2828
firewall = {
2929
subnet_address_prefix = "192.168.1.0/24"
3030
sku_tier = "Premium"
31-
sku_name = "AZFW_Hub"
31+
sku_name = "AZFW_VNet"
3232
}
3333
}
3434
}
@@ -127,31 +127,39 @@ Description: A map of the hub virtual networks to create. The map key is an arbi
127127
- `sku_name` - The name of the SKU to use for the Azure Firewall. Possible values include `AZFW_Hub`, `AZFW_VNet`.
128128
- `sku_tier` - The tier of the SKU to use for the Azure Firewall. Possible values include `Basic`, `Standard`, `Premium`.
129129
- `subnet_address_prefix` - The IPv4 address prefix to use for the Azure Firewall subnet in CIDR format. Needs to be a part of the virtual network's address space.
130-
- `subnet_route_table_id` = (Optional) The resource id of the Route Table which should be associated with the Azure Firewall subnet. If not specified the module will assign the generated route table.
131-
- `name` - (Optional) The name of the firewall resource. If not specified will use `afw-{vnetname}`.
132130
- `dns_servers` - (Optional) A list of DNS server IP addresses for the Azure Firewall.
133131
- `firewall_policy_id` - (Optional) The resource id of the Azure Firewall Policy to associate with the Azure Firewall.
132+
- `management_subnet_address_prefix` - (Optional) The IPv4 address prefix to use for the Azure Firewall management subnet in CIDR format. Needs to be a part of the virtual network's address space.
133+
- `name` - (Optional) The name of the firewall resource. If not specified will use `afw-{vnetname}`.
134134
- `private_ip_ranges` - (Optional) A list of private IP ranges to use for the Azure Firewall, to which the firewall will not NAT traffic. If not specified will use RFC1918.
135+
- `subnet_route_table_id` = (Optional) The resource id of the Route Table which should be associated with the Azure Firewall subnet. If not specified the module will assign the generated route table.
136+
- `tags` - (Optional) A map of tags to apply to the Azure Firewall. If not specified
135137
- `threat_intel_mode` - (Optional) The threat intelligence mode for the Azure Firewall. Possible values include `Alert`, `Deny`, `Off`.
136138
- `zones` - (Optional) A list of availability zones to use for the Azure Firewall. If not specified will be `null`.
137-
- `tags` - (Optional) A map of tags to apply to the Azure Firewall. If not specified
138139
- `default_ip_configuration` - (Optional) An object with the following fields. If not specified the defaults below will be used:
139140
- `name` - (Optional) The name of the default IP configuration. If not specified will use `default`.
140141
- `public_ip_config` - (Optional) An object with the following fields:
141142
- `name` - (Optional) The name of the public IP configuration. If not specified will use `pip-afw-{vnetname}`.
142143
- `zones` - (Optional) A list of availability zones to use for the public IP configuration. If not specified will be `null`.
143144
- `ip_version` - (Optional) The IP version to use for the public IP configuration. Possible values include `IPv4`, `IPv6`. If not specified will be `IPv4`.
144145
- `sku_tier` - (Optional) The SKU tier to use for the public IP configuration. Possible values include `Regional`, `Global`. If not specified will be `Regional`.
146+
- `management_ip_configuration` - (Optional) An object with the following fields. If not specified the defaults below will be used:
147+
- `name` - (Optional) The name of the management IP configuration. If not specified will use `defaultMgmt`.
148+
- `public_ip_config` - (Optional) An object with the following fields:
149+
- `name` - (Optional) The name of the public IP configuration. If not specified will use `pip-afw-mgmt-<Map Key>`.
150+
- `zones` - (Optional) A list of availability zones to use for the public IP configuration. If not specified will be `null`.
151+
- `ip_version` - (Optional) The IP version to use for the public IP configuration. Possible values include `IPv4`, `IPv6`. If not specified will be `IPv4`.
152+
- `sku_tier` - (Optional) The SKU tier to use for the public IP configuration. Possible values include `Regional`, `Global`. If not specified will be `Regional`.
145153

146154
Type:
147155

148156
```hcl
149157
map(object({
150-
name = string
151-
address_space = list(string)
152-
location = string
153-
resource_group_name = string
154-
158+
name = string
159+
address_space = list(string)
160+
location = string
161+
resource_group_name = string
162+
route_table_name = optional(string)
155163
bgp_community = optional(string)
156164
ddos_protection_plan_id = optional(string)
157165
dns_servers = optional(list(string))
@@ -204,24 +212,34 @@ map(object({
204212
)), {})
205213
206214
firewall = optional(object({
207-
sku_name = string
208-
sku_tier = string
209-
subnet_address_prefix = string
210-
subnet_route_table_id = optional(string)
211-
name = optional(string)
212-
dns_servers = optional(list(string))
213-
firewall_policy_id = optional(string)
214-
private_ip_ranges = optional(list(string))
215-
threat_intel_mode = optional(string, "Alert")
216-
zones = optional(list(string))
217-
tags = optional(map(string))
215+
sku_name = string
216+
sku_tier = string
217+
subnet_address_prefix = string
218+
dns_servers = optional(list(string))
219+
firewall_policy_id = optional(string)
220+
management_subnet_address_prefix = optional(string, null)
221+
name = optional(string)
222+
private_ip_ranges = optional(list(string))
223+
subnet_route_table_id = optional(string)
224+
tags = optional(map(string))
225+
threat_intel_mode = optional(string, "Alert")
226+
zones = optional(list(string))
218227
default_ip_configuration = optional(object({
219228
name = optional(string)
220229
public_ip_config = optional(object({
221-
name = optional(set(string))
230+
ip_version = optional(string)
231+
name = optional(string)
232+
sku_tier = optional(string, "Regional")
222233
zones = optional(set(string))
234+
}))
235+
}))
236+
management_ip_configuration = optional(object({
237+
name = optional(string)
238+
public_ip_config = optional(object({
223239
ip_version = optional(string)
240+
name = optional(string)
224241
sku_tier = optional(string, "Regional")
242+
zones = optional(set(string))
225243
}))
226244
}))
227245
}))
@@ -234,7 +252,7 @@ Default: `{}`
234252

235253
Description: Whether enable tracing tags that generated by BridgeCrew Yor.
236254

237-
Type: `string`
255+
Type: `bool`
238256

239257
Default: `false`
240258

@@ -253,8 +271,10 @@ The following resources are used by this module:
253271
- [azurerm_firewall.fw](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/firewall) (resource)
254272
- [azurerm_management_lock.rg_lock](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/management_lock) (resource)
255273
- [azurerm_public_ip.fw_default_ip_configuration_pip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) (resource)
274+
- [azurerm_public_ip.fw_management_ip_configuration_pip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) (resource)
256275
- [azurerm_resource_group.rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource)
257276
- [azurerm_route_table.hub_routing](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/route_table) (resource)
277+
- [azurerm_subnet.fw_management_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) (resource)
258278
- [azurerm_subnet.fw_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) (resource)
259279
- [azurerm_subnet_route_table_association.fw_subnet_routing_creat](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_route_table_association) (resource)
260280
- [azurerm_subnet_route_table_association.fw_subnet_routing_external](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_route_table_association) (resource)

_header.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module "hubnetworks" {
2727
firewall = {
2828
subnet_address_prefix = "192.168.1.0/24"
2929
sku_tier = "Premium"
30-
sku_name = "AZFW_Hub"
30+
sku_name = "AZFW_VNet"
3131
}
3232
}
3333
}

locals.tf

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,41 @@ locals {
1414
default_ip_configuration = {
1515
name = try(coalesce(vnet.firewall.management_ip_configuration.name, "default"), "default")
1616
}
17+
management_ip_configuration = {
18+
name = try(coalesce(vnet.firewall.management_ip_configuration.name, "defaultMgmt"), "defaultMgmt")
19+
}
1720
zones = vnet.firewall.zones
1821
} if vnet.firewall != null
1922
}
23+
firewall_management_subnets = {
24+
for k, v in var.hub_virtual_networks : k => {
25+
address_prefixes = [v.firewall.management_subnet_address_prefix]
26+
name = "AzureFirewallManagementSubnet"
27+
resource_group_name = v.resource_group_name
28+
virtual_network_name = v.name
29+
}
30+
if try(v.firewall.sku_tier, "FirewallNull") == "Basic" && v.firewall != null
31+
}
2032
fw_default_ip_configuration_pip = {
2133
for vnet_name, vnet in var.hub_virtual_networks : vnet_name => {
2234
location = local.virtual_networks_modules[vnet_name].vnet_location
23-
name = coalesce(vnet.firewall.name, "pip-afw-${vnet_name}")
35+
name = try(vnet.firewall.default_ip_configuration.public_ip_config.name, "pip-afw-${vnet_name}")
2436
resource_group_name = vnet.resource_group_name
2537
ip_version = try(vnet.firewall.default_ip_configuration.public_ip_config.ip_version, "IPv4")
2638
sku_tier = try(vnet.firewall.default_ip_configuration.public_ip_config.sku_tier, "Regional")
2739
zones = try(vnet.firewall.default_ip_configuration.public_ip_config.zones, null)
2840
} if vnet.firewall != null
2941
}
42+
fw_management_ip_configuration_pip = {
43+
for k, v in var.hub_virtual_networks : k => {
44+
location = local.virtual_networks_modules[k].vnet_location
45+
name = try(v.firewall.management_ip_configuration.public_ip_config.name, "pip-afw-mgmt-${k}")
46+
resource_group_name = v.resource_group_name
47+
ip_version = try(v.firewall.management_ip_coniguration.public_ip_config.ip_version, "IPv4")
48+
sku_tier = try(v.firewall.management_ip_coniguration.public_ip_config.sku_tier, "Regional")
49+
zones = try(v.firewall.management_ip_coniguration.public_ip_config.zones, null)
50+
} if try(v.firewall.sku_tier, "FirewallNull") == "Basic" && v.firewall != null
51+
}
3052
hub_peering_map = {
3153
for peerconfig in flatten([
3254
for k_src, v_src in var.hub_virtual_networks :
@@ -64,7 +86,7 @@ locals {
6486
name = "${k_dst}-${replace(cidr, "/", "-")}"
6587
address_prefix = cidr
6688
next_hop_type = "VirtualAppliance"
67-
next_hop_ip_address = try(local.firewall_private_ip[k_dst], v_src.hub_router_ip_address)
89+
next_hop_ip_address = try(local.firewall_private_ip[k_dst], v_dst.hub_router_ip_address)
6890
}
6991
] if k_src != k_dst && v_dst.mesh_peering_enabled && can(v_dst.routing_address_space[0])
7092
])
@@ -108,3 +130,4 @@ locals {
108130
}
109131
}
110132
}
133+

main.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ resource "azurerm_public_ip" "fw_default_ip_configuration_pip" {
132132
zones = each.value.zones
133133
}
134134

135+
resource "azurerm_public_ip" "fw_management_ip_configuration_pip" {
136+
for_each = local.fw_management_ip_configuration_pip
137+
138+
allocation_method = "Static"
139+
location = each.value.location
140+
name = each.value.name
141+
resource_group_name = each.value.resource_group_name
142+
ip_version = each.value.ip_version
143+
sku = "Standard"
144+
sku_tier = each.value.sku_tier
145+
tags = {}
146+
zones = each.value.zones
147+
}
148+
135149
resource "azurerm_subnet" "fw_subnet" {
136150
for_each = local.firewalls
137151

@@ -141,6 +155,19 @@ resource "azurerm_subnet" "fw_subnet" {
141155
virtual_network_name = module.hub_virtual_networks[each.key].vnet_name
142156
}
143157

158+
resource "azurerm_subnet" "fw_management_subnet" {
159+
for_each = local.firewall_management_subnets
160+
161+
address_prefixes = each.value.address_prefixes
162+
name = each.value.name
163+
resource_group_name = each.value.resource_group_name
164+
virtual_network_name = each.value.virtual_network_name
165+
166+
depends_on = [
167+
module.hub_virtual_networks
168+
]
169+
}
170+
144171
resource "azurerm_subnet_route_table_association" "fw_subnet_routing_creat" {
145172
for_each = { for vnet_name, fw in local.firewalls : vnet_name => fw if fw.subnet_route_table_id == null }
146173

@@ -175,4 +202,14 @@ resource "azurerm_firewall" "fw" {
175202
public_ip_address_id = azurerm_public_ip.fw_default_ip_configuration_pip[each.key].id
176203
subnet_id = azurerm_subnet.fw_subnet[each.key].id
177204
}
205+
206+
dynamic "management_ip_configuration" {
207+
for_each = each.value.sku_tier == "Basic" ? ["managementIpConfiguration"] : []
208+
209+
content {
210+
name = each.value.management_ip_configuration.name
211+
public_ip_address_id = azurerm_public_ip.fw_management_ip_configuration_pip[each.key].id
212+
subnet_id = azurerm_subnet.fw_management_subnet[each.key].id
213+
}
214+
}
178215
}

outputs.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
output "firewalls" {
22
value = {
33
for vnet_name, fw in azurerm_firewall.fw : vnet_name => {
4-
id = fw.id
5-
name = fw.name
6-
private_ip_address = try(fw.ip_configuration[0].private_ip_address, null)
7-
public_ip_address = try(azurerm_public_ip.fw_default_ip_configuration_pip[vnet_name].ip_address)
4+
id = fw.id
5+
name = fw.name
6+
private_ip_address = try(fw.ip_configuration[0].private_ip_address, null)
7+
public_ip_address = try(azurerm_public_ip.fw_default_ip_configuration_pip[vnet_name].ip_address)
8+
management_public_ip_address = try(azurerm_public_ip.fw_management_ip_configuration_pip[vnet_name].ip_address, null)
89
}
910
}
1011
description = "A curated output of the firewalls created by this module."
@@ -42,7 +43,7 @@ output "resource_groups" {
4243
output "virtual_networks" {
4344
value = {
4445
for vnet_name, vnet_mod in module.hub_virtual_networks : vnet_name => {
45-
name = vnet_name
46+
name = vnet_mod.vnet_name
4647
resource_group_name = var.hub_virtual_networks[vnet_name].resource_group_name
4748
id = vnet_mod.vnet_id
4849
location = vnet_mod.vnet_location

0 commit comments

Comments
 (0)