Bylaw

Gallery › App Service › Azure built-in policies

App Service apps should be injected into a virtual network

Converted Policy Audit Deny Disabled Mode Indexed Version 3.3.0

Injecting App Service Apps in a virtual network unlocks advanced App Service networking and security features and provides you with greater control over your network security configuration. Learn more at: https://docs.microsoft.com/azure/app-service/web-sites-integrate-with-vnet.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONApp_VNetIntegrationEnabled_Audit.json · 65 lines
{
  "properties": {
    "displayName": "App Service apps should be injected into a virtual network",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Injecting App Service Apps in a virtual network unlocks advanced App Service networking and security features and provides you with greater control over your network security configuration. Learn more at: https://docs.microsoft.com/azure/app-service/web-sites-integrate-with-vnet.",
    "metadata": {
      "version": "3.3.0",
      "category": "App Service"
    },
    "version": "3.3.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "kind",
            "notContains": "functionapp"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Web/sites/virtualNetworkSubnetId",
                "exists": false
              },
              {
                "field": "Microsoft.Web/sites/virtualNetworkSubnetId",
                "equals": ""
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "3.3.0",
      "3.2.0",
      "3.1.0",
      "3.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/72d04c29-f87d-4575-9731-419ff16a2757",
  "name": "72d04c29-f87d-4575-9731-419ff16a2757"
}
Bylaw72d04c29-f87d-4575-9731-419ff16a2757.bylaw.ps1 · 37 lines
# Converted from App_VNetIntegrationEnabled_Audit.json by ConvertTo-Bylaw.
Policy '72d04c29-f87d-4575-9731-419ff16a2757' {

    Properties @{
        DisplayName   = 'App Service apps should be injected into a virtual network'
        Description   = 'Injecting App Service Apps in a virtual network unlocks advanced App Service networking and security features and provides you with greater control over your network security configuration. Learn more at: https://docs.microsoft.com/azure/app-service/web-sites-integrate-with-vnet.'
        Version       = '3.3.0'
        Category      = 'App Service'
        PolicyVersion = '3.3.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.Web/sites' {

        When {
            Field kind | Must -Not -ContainText 'functionapp'
        }

        Require 'virtualNetworkSubnetId exists' {
            Field virtualNetworkSubnetId | Must -Exist
        }

        Require 'virtualNetworkSubnetId is not' {
            Field virtualNetworkSubnetId | Must -Not -Be '' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/App Service/App_VNetIntegrationEnabled_Audit.json in Azure/azure-policy, under the MIT licence.