Bylaw

Gallery › Cost Optimization › Azure Community Policy

Unused App Service plans driving cost should be avoided

Converted Policy Audit Disabled Mode All Version 1.0.0

Optimize cost by detecting unused but chargeable resources. Leverage this Policy definition as a cost control to reveal orphaned App Service plans that are driving cost.

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

Azure Policy JSONazurepolicy.json · 48 lines
{
  "name": "0724c16d-fd7c-46b7-adc0-bd0dfa57d4a6",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Unused App Service plans driving cost should be avoided",
    "description": "Optimize cost by detecting unused but chargeable resources. Leverage this Policy definition as a cost control to reveal orphaned App Service plans that are driving cost.",
    "metadata": {
      "version": "1.0.0",
      "category": "Cost Optimization"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/serverfarms"
          },
          {
            "field": "Microsoft.Web/serverFarms/sku.tier",
            "notEquals": "Free"
          },
          {
            "field": "Microsoft.Web/serverFarms/numberOfSites",
            "equals": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw0724c16d-fd7c-46b7-adc0-bd0dfa57d4a6.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '0724c16d-fd7c-46b7-adc0-bd0dfa57d4a6' {

    Properties @{
        DisplayName = 'Unused App Service plans driving cost should be avoided'
        Description = 'Optimize cost by detecting unused but chargeable resources. Leverage this Policy definition as a cost control to reveal orphaned App Service plans that are driving cost.'
        Version     = '1.0.0'
        Category    = 'Cost Optimization'
        Mode        = 'All'
    }

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

    Resource 'Microsoft.Web/serverfarms' {

        When {
            Field sku.tier | Must -Not -Be 'Free'
        }

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

    Effect (Param Effect)
}

Source: policyDefinitions/Cost Optimization/unused-app-service-plans-driving-cost-should-be-avoided/azurepolicy.json in Azure/Community-Policy, under the MIT licence.