Azure Network Firewall
This page shows how to write Terraform and Azure Resource Manager for Network Firewall and write them securely.
azurerm_firewall (Terraform)
The Firewall in Network can be configured in Terraform with the resource name azurerm_firewall. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_firewall" "standard" {
name = "testfirewall"
location = "eastus"
resource_group_name = azurerm_resource_group.example.name
ip_configuration {
resource "azurerm_firewall" "az_firewall" {
name = var.name
location = var.location
resource_group_name = var.resource_group_name
tags = local.tags
resource "azurerm_firewall" "standard" {
name = "testfirewall"
location = "eastus"
resource_group_name = azurerm_resource_group.example.name
ip_configuration {
resource "azurerm_firewall" "fw" {
name = var.res_fw_name
location = var.res_location
resource_group_name = var.res_fw_rg_name
tags = var.res_tags
resource "azurerm_firewall" "firewall" {
name = var.firewallname
location = var.location
resource_group_name = var.resourcegroup_name
ip_configuration {
resource "azurerm_firewall" "fw" {
name = var.fw_name
location = var.location
resource_group_name = var.resource_group
ip_configuration {
resource "azurerm_firewall" "example" {
name = "testfirewall"
location = var.location
resource_group_name = var.resourceGroupName
ip_configuration {
resource "azurerm_firewall" "firewall" {
name = local.firewall_name
location = azurerm_resource_group.hub.location
resource_group_name = azurerm_resource_group.hub.name
ip_configuration {
resource "azurerm_firewall" "vnet-hub-firewall" {
name = "hubfirewall"
location = data.azurerm_resource_group.main_rg.location
resource_group_name = data.azurerm_resource_group.main_rg.name
ip_configuration {
resource "azurerm_firewall" "azfwall" {
name = "azfwall"
location = azurerm_resource_group.spoke2-vnet-rg.location
resource_group_name = azurerm_resource_group.spoke2-vnet-rg.name
ip_configuration {
Parameters
-
dns_serversoptional - list of string -
firewall_policy_idoptional - string -
idoptional computed - string -
locationrequired - string -
namerequired - string -
private_ip_rangesoptional - set of string -
resource_group_namerequired - string -
sku_nameoptional computed - string -
sku_tieroptional computed - string -
tagsoptional - map from string to string -
threat_intel_modeoptional - string -
zonesoptional - list of string -
ip_configurationlist block-
namerequired - string -
private_ip_addressoptional computed - string -
public_ip_address_idrequired - string -
subnet_idoptional - string
-
-
management_ip_configurationlist block-
namerequired - string -
private_ip_addressoptional computed - string -
public_ip_address_idrequired - string -
subnet_idrequired - string
-
-
timeoutssingle block -
virtual_hublist block-
private_ip_addressoptional computed - string -
public_ip_addressesoptional computed - list of string -
public_ip_countoptional - number -
virtual_hub_idrequired - string
-
Explanation in Terraform Registry
Manages an Azure Firewall.
Tips: Best Practices for The Other Azure Network Resources
In addition to the azurerm_network_security_group, Azure Network has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_network_security_group
Ensure to disable RDP port from the Internet
It is better to disable the RDP port from the Internet. RDP access should not be accepted from the Internet (*, 0.0.0.0, /0, internet, any), and consider using the Azure Bastion Service.
azurerm_network_security_rule
Ensure to set a more restrictive CIDR range for ingress from the internet
It is better to set a more restrictive CIDR range not to use very broad subnets. If possible, segments should be divided into smaller subnets.
azurerm_network_watcher_flow_log
Ensure to enable Retention policy for flow logs and set it to enough duration
It is better to enable a retention policy for flow logs. Flow logs show us all network activity in the cloud environment and support us when we face critical incidents.
Microsoft.Network/azureFirewalls (Azure Resource Manager)
The azureFirewalls in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/azureFirewalls. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"Type": "Microsoft.Network/azureFirewalls",
"ResourceType": "Microsoft.Network/azureFirewalls",
"ExtensionResourceType": null,
"Sku": null,
"SubscriptionId": "00000000-0000-0000-0000-000000000000"
},
"type": "Microsoft.Network/azureFirewalls",
"apiVersion": "2020-08-01",
"location": "West Europe",
"properties": {
"networkRuleCollections": [
{
"type": "Microsoft.Network/azureFirewalls",
"apiVersion": "2020-08-01",
"location": "West Europe",
"properties": {
"networkRuleCollections": [
{
"type": "Microsoft.Network/azureFirewalls"
}
"type": "Microsoft.Network/azureFirewalls",
"name": "[parameters('firewallName')]",
"location": "[parameters('location')]",
"zones": "[if(equals(length(parameters('availabilityZones')), 0), json('null'), parameters('availabilityZones'))]",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses/', parameters('publicIPName'))]"
"type": "Microsoft.Network/azureFirewalls",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"properties": {
"virtualHub": {
"id": "[parameters('vwan_id')]"
"type": "Microsoft.Network/azureFirewalls",
"apiVersion": "2019-04-01",
"location": "string",
"tags": {},
"properties": {
"applicationRuleCollections": [
"type": "Microsoft.Network/azureFirewalls",
"name": "[parameters('azureFirewallName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', variables('azureFirewallPipName'))]"
],
"type": "Microsoft.Network/azureFirewalls",
"name": "[variables('firewallName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/virtualNetworks/', parameters('vnet_name'))]",
"[concat('Microsoft.Network/publicIPAddresses/', variables('FwPublicIPName'))]"
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "0.1.0.0",
"parameters": {
"FirewallName": {
Parameters
namerequired - stringtyperequired - stringapiVersionrequired - stringlocationrequired - stringResource location.
tagsoptional - stringResource tags.
propertiesrequiredapplicationRuleCollectionsoptional arraypropertiesoptionalpriorityoptional - integerPriority of the application rule collection resource.
actionoptionaltypeoptional - stringThe type of action.
rulesoptional arraynameoptional - stringName of the application rule.
descriptionoptional - stringDescription of the rule.
sourceAddressesoptional - arrayList of source IP addresses for this rule.
protocolsoptional arrayprotocolTypeoptional - stringProtocol type.
portoptional - integerPort number for the protocol, cannot be greater than 64000. This field is optional.
targetFqdnsoptional - arrayList of FQDNs for this rule.
fqdnTagsoptional - arrayList of FQDN Tags for this rule.
sourceIpGroupsoptional - arrayList of source IpGroups for this rule.
nameoptional - stringThe name of the resource that is unique within the Azure firewall. This name can be used to access the resource.
natRuleCollectionsoptional arraypropertiesoptionalpriorityoptional - integerPriority of the NAT rule collection resource.
actionoptionaltypeoptional - stringThe type of action.
rulesoptional arraynameoptional - stringName of the NAT rule.
descriptionoptional - stringDescription of the rule.
sourceAddressesoptional - arrayList of source IP addresses for this rule.
destinationAddressesoptional - arrayList of destination IP addresses for this rule. Supports IP ranges, prefixes, and service tags.
destinationPortsoptional - arrayList of destination ports.
protocolsoptional - arrayArray of AzureFirewallNetworkRuleProtocols applicable to this NAT rule.
translatedAddressoptional - stringThe translated address for this NAT rule.
translatedPortoptional - stringThe translated port for this NAT rule.
translatedFqdnoptional - stringThe translated FQDN for this NAT rule.
sourceIpGroupsoptional - arrayList of source IpGroups for this rule.
nameoptional - stringThe name of the resource that is unique within the Azure firewall. This name can be used to access the resource.
networkRuleCollectionsoptional arraypropertiesoptionalpriorityoptional - integerPriority of the network rule collection resource.
actionoptionaltypeoptional - stringThe type of action.
rulesoptional arraynameoptional - stringName of the network rule.
descriptionoptional - stringDescription of the rule.
protocolsoptional - arrayArray of AzureFirewallNetworkRuleProtocols.
sourceAddressesoptional - arrayList of source IP addresses for this rule.
destinationAddressesoptional - arrayList of destination IP addresses.
destinationPortsoptional - arrayList of destination ports.
destinationFqdnsoptional - arrayList of destination FQDNs.
sourceIpGroupsoptional - arrayList of source IpGroups for this rule.
destinationIpGroupsoptional - arrayList of destination IpGroups for this rule.
nameoptional - stringThe name of the resource that is unique within the Azure firewall. This name can be used to access the resource.
ipConfigurationsoptional arraypropertiesoptionalsubnetoptionalidrequired - stringResource ID.
publicIPAddressoptionalidrequired - stringResource ID.
nameoptional - stringName of the resource that is unique within a resource group. This name can be used to access the resource.
managementIpConfigurationoptionalpropertiesoptionalsubnetoptionalidrequired - stringResource ID.
publicIPAddressoptionalidrequired - stringResource ID.
nameoptional - stringName of the resource that is unique within a resource group. This name can be used to access the resource.
threatIntelModeoptional - stringThe operation mode for Threat Intelligence.
virtualHuboptionalidrequired - stringResource ID.
firewallPolicyoptionalidrequired - stringResource ID.
hubIPAddressesoptionalpublicIPsoptionaladdressesoptional arrayaddressoptional - stringPublic IP Address value.
countoptional - integerThe number of Public IP addresses associated with azure firewall.
privateIPAddressoptional - stringPrivate IP Address associated with azure firewall.
skuoptionalnameoptional - stringName of an Azure Firewall SKU.
tieroptional - stringTier of an Azure Firewall.
additionalPropertiesoptional - stringThe additional properties used to further config this azure firewall.
zonesoptional - arrayA list of availability zones denoting where the resource needs to come from.
Frequently asked questions
What is Azure Network Firewall?
Azure Network Firewall is a resource for Network of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Network Firewall?
For Terraform, the gilyas/infracost, BrettOJ/azuread_adfs_jwt_token and infracost/infracost source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the Azure/PSRule.Rules.Azure, snyk/snyk and snyk/snyk source code examples are useful. See the Azure Resource Manager Example section for further details.