Azure Policy: Restrict Azure Functions from using Consumption Plan

Azure Functions can either use a Consumption or a Premium/Dedicated/other for execution and pricing.

Consumption plans are good when you want to stay dynamic in terms of how you want to scale up based on the utilization and you can have more spread out usage throughout your tenant. When it comes to pricing, Azure Functions running on Consumption plan are least predictive since the pricing is based on the number of executions of those Azure Functions. If an Azure Function, hosted using Consumption plan executes n1 number of times, then the pricing would be m1, and if it executes n2 number of times, then the pricing would be m2. In other words, highly unpredictable and one school of thought says that its production use has only very limited use cases.

Thanks to the Azure Policy governance that runs on top of Azure, we can build a small Azure policy and apply it in our subscription to stop anyone ever spinning an Azure Function on Consumption plan. The keyword here in this policy is the SKU of Y1. if there’s every a Function Plan SKU Y1, it will be flagged in this policy.

{
  "mode": "All",
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.Web/serverfarms"
        },
        {
          "field": "Microsoft.Web/serverfarms/sku.name",
          "equals": "Y1"
        }
      ]
    },
    "then": {
      "effect": "[parameters('effect')]",
      "details": {
        "type": "Microsoft.Web/serverfarms"
      }
    }
  },
  "parameters": {
    "effect": {
      "type": "String",
      "metadata": {
        "displayName": "Effect",
        "description": "Enable or disable the execution of the policy"
      },
      "allowedValues": [
        "Audit",
        "Deny",
        "Disabled"
      ],
      "defaultValue": "Deny"
    }
  }
}

 

Leave a Reply