Bylaw

Gallery › App Service › Azure built-in policies

[Deprecated]: Ensure that 'PHP version' is the latest, if used as a part of the Function app

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0-deprecated Deprecated

PHP cannot be used with Function apps.

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

Azure Policy JSONFunctionApp_Audit_PHP_Latest.json · 102 lines
{
  "properties": {
    "displayName": "[Deprecated]: Ensure that 'PHP version' is the latest, if used as a part of the Function app",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "PHP cannot be used with Function apps.",
    "metadata": {
      "version": "1.0.0-deprecated",
      "category": "App Service",
      "deprecated": true
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      },
      "PHPLatestVersion": {
        "type": "String",
        "defaultValue": "7.3",
        "metadata": {
          "displayName": "Latest PHP version",
          "description": "Latest supported PHP version for App Services"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "kind",
            "like": "functionapp*"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Web/sites/config",
          "name": "web",
          "existenceCondition": {
            "anyOf": [
              {
                "allOf": [
                  {
                    "field": "Microsoft.Web/sites/config/web.linuxFxVersion",
                    "notContains": "PHP"
                  },
                  {
                    "field": "Microsoft.Web/sites/config/web.phpVersion",
                    "equals": ""
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Web/sites/config/web.linuxFxVersion",
                    "equals": "[concat('PHP|', parameters('PHPLatestVersion'))]"
                  },
                  {
                    "field": "Microsoft.Web/sites/config/web.phpVersion",
                    "equals": ""
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.Web/sites/config/web.linuxFxVersion",
                    "equals": ""
                  },
                  {
                    "field": "Microsoft.Web/sites/config/web.phpVersion",
                    "equals": "[parameters('PHPLatestVersion')]"
                  }
                ]
              }
            ]
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/ab965db2-d2bf-4b64-8b39-c38ec8179461",
  "name": "ab965db2-d2bf-4b64-8b39-c38ec8179461"
}
Bylawab965db2-d2bf-4b64-8b39-c38ec8179461.bylaw.ps1 · 53 lines
# Converted from FunctionApp_Audit_PHP_Latest.json by ConvertTo-Bylaw.
Policy 'ab965db2-d2bf-4b64-8b39-c38ec8179461' {

    Properties @{
        DisplayName   = '[Deprecated]: Ensure that ''PHP version'' is the latest, if used as a part of the Function app'
        Description   = 'PHP cannot be used with Function apps.'
        Version       = '1.0.0-deprecated'
        Category      = 'App Service'
        Deprecated    = $true
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter PHPLatestVersion @{
        Default     = '7.3'
        DisplayName = 'Latest PHP version'
        Description = 'Latest supported PHP version for App Services'
        JsonName    = 'PHPLatestVersion'
    }

    Resource 'Microsoft.Web/sites' {

        Require 'kind is not like functionapp*' {
            Field kind | Must -Not -BeLike 'functionapp*' -IfPresent
        }
    }

    AuditIfNotExists 'Microsoft.Web/sites/config' -Name 'web' -Effect (Param Effect) {
        Require 'web.linuxFxVersion and web.phpVersion are as required' {
            AnyOf {
                AllOf {
                    Field web.linuxFxVersion | Must -Not -ContainText 'PHP' -IfPresent
                    Field web.phpVersion | Must -Be ''
                }
                AllOf {
                    Field web.linuxFxVersion | Must -Be (Arm '[concat(''PHP|'', parameters(''PHPLatestVersion''))]')
                    Field web.phpVersion | Must -Be ''
                }
                AllOf {
                    Field web.linuxFxVersion | Must -Be ''
                    Field web.phpVersion | Must -Be (Param PHPLatestVersion)
                }
            }
        }
    }
}

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