Bylaw

Gallery › App Service › Azure Community Policy

Function apps should be injected into a virtual network

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0

Injecting function 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 JSONazurepolicy.json · 52 lines
{
  "name": "fae71f6c-773b-4953-81d9-4f23c5499d8c",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Function apps should be injected into a virtual network",
    "description": "Injecting function 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": "1.0.0",
      "category": "App Service"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "AuditIfNotExists or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "kind",
            "contains": "functionapp"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Web/sites/networkConfig",
          "name": "virtualNetwork",
          "existenceCondition": {
            "field": "Microsoft.Web/sites/networkConfig/subnetResourceId",
            "notEquals": ""
          }
        }
      }
    }
  }
}
Bylawfae71f6c-773b-4953-81d9-4f23c5499d8c.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'fae71f6c-773b-4953-81d9-4f23c5499d8c' {

    Properties @{
        DisplayName = 'Function apps should be injected into a virtual network'
        Description = 'Injecting function 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     = '1.0.0'
        Category    = 'App Service'
        Mode        = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'AuditIfNotExists or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Web/sites' {

        Require 'kind does not contain functionapp' {
            Field kind | Must -Not -ContainText 'functionapp' -IfPresent
        }
    }

    AuditIfNotExists 'Microsoft.Web/sites/networkConfig' -Name 'virtualNetwork' -Effect (Param Effect) {
        Require 'subnetResourceId is not' {
            Field subnetResourceId | Must -Not -Be '' -IfPresent
        }
    }
}

Source: policyDefinitions/App Service/function-apps-should-be-injected-into-a-virtual-network/azurepolicy.json in Azure/Community-Policy, under the MIT licence.