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

firewall_test.tf#L47
resource "azurerm_firewall" "standard" {
  name                = "testfirewall"
  location            = "eastus"
  resource_group_name = azurerm_resource_group.example.name

  ip_configuration {
azure-firewall.tf#L3
resource "azurerm_firewall" "az_firewall" {
  name                = var.name
  location            = var.location
  resource_group_name = var.resource_group_name
  tags                = local.tags

firewall_test.tf#L47
resource "azurerm_firewall" "standard" {
  name                = "testfirewall"
  location            = "eastus"
  resource_group_name = azurerm_resource_group.example.name

  ip_configuration {
resource.tf#L1
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

firewall.tf#L18
resource "azurerm_firewall" "firewall" {
  name                = var.firewallname
  location            = var.location
  resource_group_name = var.resourcegroup_name

  ip_configuration {
firewall.tf#L9
resource "azurerm_firewall" "fw" {
  name                = var.fw_name
  location            = var.location
  resource_group_name = var.resource_group

  ip_configuration {
main.tf#L33
resource "azurerm_firewall" "example" {
  name                = "testfirewall"
  location            = var.location
  resource_group_name = var.resourceGroupName

  ip_configuration {
firewall.tf#L9
resource "azurerm_firewall" "firewall" {
  name                = local.firewall_name
  location            = azurerm_resource_group.hub.location
  resource_group_name = azurerm_resource_group.hub.name

  ip_configuration {
firewall.tf#L16
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 {
AzureFirewall.tf#L9
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 {

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

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.

risk-label

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.

risk-label

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.

risk-label

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.

Review your Azure Network settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

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

Resources.Firewall.json#L42
        "Type": "Microsoft.Network/azureFirewalls",
        "ResourceType": "Microsoft.Network/azureFirewalls",
        "ExtensionResourceType": null,
        "Sku": null,
        "SubscriptionId": "00000000-0000-0000-0000-000000000000"
    },
invalid_rule_test.json#L8
      "type": "Microsoft.Network/azureFirewalls",
      "apiVersion": "2020-08-01",
      "location": "West Europe",
      "properties": {
        "networkRuleCollections": [
          {
rule_test.json#L9
      "type": "Microsoft.Network/azureFirewalls",
      "apiVersion": "2020-08-01",
      "location": "West Europe",
      "properties": {
        "networkRuleCollections": [
          {
test-get-expected.json#L20
    "type": "Microsoft.Network/azureFirewalls"
  }
azuredeploy.json#L147
            "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'))]"
arm_template_vhub_firewall.json#L38
      "type": "Microsoft.Network/azureFirewalls",
      "name": "[parameters('name')]",
      "location": "[parameters('location')]",
      "properties": {
          "virtualHub": {
              "id": "[parameters('vwan_id')]"
azurefirewalls.json#L3
  "type": "Microsoft.Network/azureFirewalls",
  "apiVersion": "2019-04-01",
  "location": "string",
  "tags": {},
  "properties": {
    "applicationRuleCollections": [
deploy.json#L129
            "type": "Microsoft.Network/azureFirewalls",
            "name": "[parameters('azureFirewallName')]",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[resourceId('Microsoft.Network/publicIPAddresses', variables('azureFirewallPipName'))]"
            ],
deploy-vnetfw.json#L99
            "type": "Microsoft.Network/azureFirewalls",
            "name": "[variables('firewallName')]",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[concat('Microsoft.Network/virtualNetworks/', parameters('vnet_name'))]",
                "[concat('Microsoft.Network/publicIPAddresses/', variables('FwPublicIPName'))]"
AzFwDeployDiag.json
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "0.1.0.0",
    "parameters": {
        "FirewallName": {

Parameters

  • name required - string
  • type required - string
  • apiVersion required - string
  • location required - string

    Resource location.

  • tags optional - string

    Resource tags.

  • properties required
      • applicationRuleCollections optional array
          • properties optional
              • priority optional - integer

                Priority of the application rule collection resource.

              • action optional
                  • type optional - string

                    The type of action.

              • rules optional array
                  • name optional - string

                    Name of the application rule.

                  • description optional - string

                    Description of the rule.

                  • sourceAddresses optional - array

                    List of source IP addresses for this rule.

                  • protocols optional array
                      • protocolType optional - string

                        Protocol type.

                      • port optional - integer

                        Port number for the protocol, cannot be greater than 64000. This field is optional.

                  • targetFqdns optional - array

                    List of FQDNs for this rule.

                  • fqdnTags optional - array

                    List of FQDN Tags for this rule.

                  • sourceIpGroups optional - array

                    List of source IpGroups for this rule.

          • name optional - string

            The name of the resource that is unique within the Azure firewall. This name can be used to access the resource.

      • natRuleCollections optional array
          • properties optional
              • priority optional - integer

                Priority of the NAT rule collection resource.

              • action optional
                  • type optional - string

                    The type of action.

              • rules optional array
                  • name optional - string

                    Name of the NAT rule.

                  • description optional - string

                    Description of the rule.

                  • sourceAddresses optional - array

                    List of source IP addresses for this rule.

                  • destinationAddresses optional - array

                    List of destination IP addresses for this rule. Supports IP ranges, prefixes, and service tags.

                  • destinationPorts optional - array

                    List of destination ports.

                  • protocols optional - array

                    Array of AzureFirewallNetworkRuleProtocols applicable to this NAT rule.

                  • translatedAddress optional - string

                    The translated address for this NAT rule.

                  • translatedPort optional - string

                    The translated port for this NAT rule.

                  • translatedFqdn optional - string

                    The translated FQDN for this NAT rule.

                  • sourceIpGroups optional - array

                    List of source IpGroups for this rule.

          • name optional - string

            The name of the resource that is unique within the Azure firewall. This name can be used to access the resource.

      • networkRuleCollections optional array
          • properties optional
              • priority optional - integer

                Priority of the network rule collection resource.

              • action optional
                  • type optional - string

                    The type of action.

              • rules optional array
                  • name optional - string

                    Name of the network rule.

                  • description optional - string

                    Description of the rule.

                  • protocols optional - array

                    Array of AzureFirewallNetworkRuleProtocols.

                  • sourceAddresses optional - array

                    List of source IP addresses for this rule.

                  • destinationAddresses optional - array

                    List of destination IP addresses.

                  • destinationPorts optional - array

                    List of destination ports.

                  • destinationFqdns optional - array

                    List of destination FQDNs.

                  • sourceIpGroups optional - array

                    List of source IpGroups for this rule.

                  • destinationIpGroups optional - array

                    List of destination IpGroups for this rule.

          • name optional - string

            The name of the resource that is unique within the Azure firewall. This name can be used to access the resource.

      • ipConfigurations optional array
          • properties optional
              • subnet optional
                  • id required - string

                    Resource ID.

              • publicIPAddress optional
                  • id required - string

                    Resource ID.

          • name optional - string

            Name of the resource that is unique within a resource group. This name can be used to access the resource.

      • managementIpConfiguration optional
          • properties optional
              • subnet optional
                  • id required - string

                    Resource ID.

              • publicIPAddress optional
                  • id required - string

                    Resource ID.

          • name optional - string

            Name of the resource that is unique within a resource group. This name can be used to access the resource.

      • threatIntelMode optional - string

        The operation mode for Threat Intelligence.

      • virtualHub optional
          • id required - string

            Resource ID.

      • firewallPolicy optional
          • id required - string

            Resource ID.

      • hubIPAddresses optional
          • publicIPs optional
              • addresses optional array
                  • address optional - string

                    Public IP Address value.

              • count optional - integer

                The number of Public IP addresses associated with azure firewall.

          • privateIPAddress optional - string

            Private IP Address associated with azure firewall.

      • sku optional
          • name optional - string

            Name of an Azure Firewall SKU.

          • tier optional - string

            Tier of an Azure Firewall.

      • additionalProperties optional - string

        The additional properties used to further config this azure firewall.

  • zones optional - array

    A 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.