Azure Network Firewall Policy

This page shows how to write Terraform and Azure Resource Manager for Network Firewall Policy and write them securely.

azurerm_web_application_firewall_policy (Terraform)

The Firewall Policy in Network can be configured in Terraform with the resource name azurerm_web_application_firewall_policy. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

wafpolicies.tf#L3
resource "azurerm_web_application_firewall_policy" "global" {
  name                = "global-wafpolicy"
  resource_group_name = var.resource_group_name
  location            = var.location
  tags                = var.tags

appgw_wafpolicy.tf#L1
resource "azurerm_web_application_firewall_policy" "tfrg" {
  name                = "test-wafpolicy"
  resource_group_name = azurerm_resource_group.tfrg.name
  location            = var.location

  custom_rules {
main.tf#L7
resource "azurerm_web_application_firewall_policy" "this" {
  location            = var.location
  name                = var.name
  resource_group_name = var.resource_group_name
  tags                = var.tags

main.tf#L1
resource "azurerm_web_application_firewall_policy" "example" {
  name                = var.wafpolicyname
  resource_group_name = var.wafrg_name
  location            = var.wafrg_loc

  custom_rules {
main.tf#L1
resource "azurerm_web_application_firewall_policy" "example" {
  name                = var.wafpolicyname
  resource_group_name = var.wafrg_name
  location            = var.wafrg_loc

  custom_rules {
main.tf#L1
resource "azurerm_web_application_firewall_policy" "example" {
  name                = var.wafpolicyname
  resource_group_name = var.wafrg_name
  location            = var.wafrg_loc

  custom_rules {
module.tf#L1
resource "azurerm_web_application_firewall_policy" "app-gw-policy" {
  for_each                          = var.app-gw-waf-object
  name                              = each.value.name
  resource_group_name               = var.app-gw-rg
  location                          = var.location
  tags                              = var.tags
main.tf#L1
resource "azurerm_web_application_firewall_policy" "wafpolicy" {

  name                = var.settings.name
  resource_group_name = var.resource_group_name
  location            = var.location
  tags                = var.tags
main.tf#L10
resource "azurerm_web_application_firewall_policy" "waf" {
  resource_group_name = local.resourcegroup_state_exists == true ? var.resource_group_name : data.azurerm_resource_group.rg_search.0.name
  location = local.resourcegroup_state_exists == true ? var.resource_group_location : data.azurerm_resource_group.rg_search.0.location
  for_each = var.waf_variable
  name     = each.value["waf_name"]

appfw.tf#L1
resource "azurerm_web_application_firewall_policy" "aagwaf" {
  name                = "example-wafpolicy"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location

  custom_rules {

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 a Azure Web Application Firewall Policy instance.

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/ApplicationGatewayWebApplicationFirewallPolicies (Azure Resource Manager)

The ApplicationGatewayWebApplicationFirewallPolicies in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

azuredeploy.json#L23
            "type": "Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies",
            "apiVersion": "2020-05-01",
            "name": "[variables('ApplicationGatewayWebApplicationFirewallPolicyPrimaryName')]",
            "location": "[parameters('location')]",
            "properties": {
                "customRules": [
Microsoft.Network.AppGwWebApplicationFirewallPolicies.tests.json#L8
        "type":"Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies",
        "name":"[variables('policyName')]",
        "location":"[resourceGroup().location]",
        "properties":{
          "customRules": []
        }
Microsoft.Network.AppGwWebApplicationFirewallPolicies.tests.json#L8
        "type":"Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies",
        "name":"[variables('policyName')]",
        "location":"[resourceGroup().location]",
        "properties":{
          "customRules": []
        }
Microsoft.Network.AppGwWebApplicationFirewallPolicies.tests.json#L8
        "type":"Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies",
        "name":"[variables('policyName')]",
        "location":"[resourceGroup().location]",
        "properties":{
          "customRules": []
        }
Microsoft.Network.AppGwWebApplicationFirewallPolicies.tests.json#L8
        "type":"Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies",
        "name":"[variables('policyName')]",
        "location":"[resourceGroup().location]",
        "properties":{
          "customRules": []
        }
Microsoft.Network.AppGwWebApplicationFirewallPolicies.tests.json#L8
        "type":"Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies",
        "name":"[variables('policyName')]",
        "location":"[resourceGroup().location]",
        "properties":{
          "customRules": []
        }
applicationgatewaywebapplicationfirewallpolicies.json#L3
  "type": "Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies",
  "apiVersion": "2019-04-01",
  "location": "string",
  "tags": {},
  "properties": {
    "policySettings": {
Microsoft.Network.AppGwWebApplicationFirewallPolicy.tests.json#L8
        "type": "Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies",
        "name": "[variables('policyName')]",
        "location": "[resourceGroup().location]",
        "properties": {
          "customRules": [],
          "managedRules": {
Microsoft.Network.AppGwWebApplicationFirewallPolicy.tests.json#L8
        "type": "Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies",
        "name": "[variables('policyName')]",
        "location": "[resourceGroup().location]",
        "properties": {
          "customRules": [],
          "managedRules": {
Microsoft.Network.AppGwWebApplicationFirewallPolicy.tests.json#L8
        "type": "Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies",
        "name": "[variables('policyName')]",
        "location": "[resourceGroup().location]",
        "properties": {
          "customRules": [],
          "managedRules": {

Parameters

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

    Resource location.

  • tags optional - string

    Resource tags.

  • properties required
      • policySettings optional
          • state optional - string

            The state of the policy.

          • mode optional - string

            The mode of the policy.

          • requestBodyCheck optional - boolean

            Whether to allow WAF to check request Body.

          • maxRequestBodySizeInKb optional - integer

            Maximum request body size in Kb for WAF.

          • fileUploadLimitInMb optional - integer

            Maximum file upload size in Mb for WAF.

      • customRules optional array
          • name optional - string

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

          • priority required - integer

            Priority of the rule. Rules with a lower value will be evaluated before rules with a higher value.

          • ruleType required - string

            The rule type.

          • matchConditions required array
              • matchVariables required array
                  • variableName required - string

                    Match Variable.

                  • selector optional - string

                    The selector of match variable.

              • operator required - string

                The operator to be matched.

              • negationConditon optional - boolean

                Whether this is negate condition or not.

              • matchValues required - array

                Match value.

              • transforms optional - array

                List of transforms.

          • action required - string

            Type of Actions.

      • managedRules required
          • exclusions optional array
              • matchVariable required - string

                The variable to be excluded.

              • selectorMatchOperator required - string

                When matchVariable is a collection, operate on the selector to specify which elements in the collection this exclusion applies to.

              • selector required - string

                When matchVariable is a collection, operator used to specify which elements in the collection this exclusion applies to.

          • managedRuleSets required array
              • ruleSetType required - string

                Defines the rule set type to use.

              • ruleSetVersion required - string

                Defines the version of the rule set to use.

              • ruleGroupOverrides optional array
                  • ruleGroupName required - string

                    The managed rule group to override.

                  • rules optional array
                      • ruleId required - string

                        Identifier for the managed rule.

                      • state optional - string

                        The state of the managed rule. Defaults to Disabled if not specified.

Frequently asked questions

What is Azure Network Firewall Policy?

Azure Network Firewall Policy 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 Policy?

For Terraform, the SGGIRBS/terraform-appgw-module, iljoong/azure-waf-automation and kevinhead/azurerm source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the briandenicola/cqrs, Azure/azure-resource-manager-schemas and Azure/azure-resource-manager-schemas source code examples are useful. See the Azure Resource Manager Example section for further details.