Bylaw

Gallery › Cost Optimization › Azure Landing Zones Library

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 JSONAudit-ServerFarms-UnusedResourcesCostOptimization.alz_policy_definition.json · 55 lines
{
  "name": "Audit-ServerFarms-UnusedResourcesCostOptimization",
  "properties": {
    "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.",
    "displayName": "Unused App Service plans driving cost should be avoided",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud",
        "AzureChinaCloud",
        "AzureUSGovernment"
      ],
      "category": "Cost Optimization",
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.0.0"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit",
        "metadata": {
          "description": "Enable or disable the execution of the policy",
          "displayName": "Effect"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.Web/serverfarms",
            "field": "type"
          },
          {
            "field": "Microsoft.Web/serverFarms/sku.tier",
            "notEquals": "Free"
          },
          {
            "equals": 0,
            "field": "Microsoft.Web/serverFarms/numberOfSites"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawAudit-ServerFarms-UnusedResourcesCostOptimization.bylaw.ps1 · 32 lines
# Converted from Audit-ServerFarms-UnusedResourcesCostOptimization.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Audit-ServerFarms-UnusedResourcesCostOptimization' {

    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.'
        Category    = 'Cost Optimization'
        Version     = '1.0.0'
        Mode        = 'All'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/' }
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable 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: policy_definitions/Audit-ServerFarms-UnusedResourcesCostOptimization.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.