Bylaw

Gallery › App Service › Azure built-in policies

App Service app slots should use an Azure file share for its content directory

Converted Policy Audit Disabled Mode Indexed Version 1.0.0

The content directory of an app should be located on an Azure file share. The storage account information for the file share must be provided before any publishing activity. To learn more about using Azure Files for hosting app service content refer to https://go.microsoft.com/fwlink/?linkid=2151594.

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

Azure Policy JSONWebApp_Slot_StorageAccountRequired_Audit.json · 53 lines
{
  "properties": {
    "displayName": "App Service app slots should use an Azure file share for its content directory",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "The content directory of an app should be located on an Azure file share. The storage account information for the file share must be provided before any publishing activity. To learn more about using Azure Files for hosting app service content refer to https://go.microsoft.com/fwlink/?linkid=2151594.",
    "metadata": {
      "version": "1.0.0",
      "category": "App Service"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites/slots"
          },
          {
            "field": "kind",
            "notContains": "functionapp"
          },
          {
            "field": "Microsoft.Web/sites/slots/storageAccountRequired",
            "equals": "true"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/fd34e936-069e-4fe5-bac6-f7c9824caab6",
  "name": "fd34e936-069e-4fe5-bac6-f7c9824caab6"
}
Bylawfd34e936-069e-4fe5-bac6-f7c9824caab6.bylaw.ps1 · 33 lines
# Converted from WebApp_Slot_StorageAccountRequired_Audit.json by ConvertTo-Bylaw.
Policy 'fd34e936-069e-4fe5-bac6-f7c9824caab6' {

    Properties @{
        DisplayName   = 'App Service app slots should use an Azure file share for its content directory'
        Description   = 'The content directory of an app should be located on an Azure file share. The storage account information for the file share must be provided before any publishing activity. To learn more about using Azure Files for hosting app service content refer to https://go.microsoft.com/fwlink/?linkid=2151594.'
        Version       = '1.0.0'
        Category      = 'App Service'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Web/sites/slots' {

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

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

    Effect (Param Effect)
}

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