Bylaw

Gallery › Cost Optimization › Azure Landing Zones Library

Unused Disks 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 Disks that are driving cost.

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

Azure Policy JSONAudit-Disks-UnusedResourcesCostOptimization.alz_policy_definition.json · 67 lines
{
  "name": "Audit-Disks-UnusedResourcesCostOptimization",
  "properties": {
    "description": "Optimize cost by detecting unused but chargeable resources. Leverage this Policy definition as a cost control to reveal orphaned Disks that are driving cost.",
    "displayName": "Unused Disks 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.Compute/disks",
            "field": "type"
          },
          {
            "equals": "Unattached",
            "field": "Microsoft.Compute/disks/diskState"
          },
          {
            "allof": [
              {
                "field": "name",
                "notlike": "*-ASRReplica"
              },
              {
                "field": "name",
                "notlike": "ms-asr-*"
              },
              {
                "field": "name",
                "notlike": "asrseeddisk-*"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawAudit-Disks-UnusedResourcesCostOptimization.bylaw.ps1 · 34 lines
# Converted from Audit-Disks-UnusedResourcesCostOptimization.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Audit-Disks-UnusedResourcesCostOptimization' {

    Properties @{
        DisplayName = 'Unused Disks 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 Disks 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.Compute/disks' {

        When {
            Field diskState | Must -Be 'Unattached'
            Field name | Must -Not -BeLike '*-ASRReplica'
            Field name | Must -Not -BeLike 'ms-asr-*'
        }

        Require 'name is like asrseeddisk-*' {
            Field name | Must -BeLike 'asrseeddisk-*'
        }
    }

    Effect (Param Effect)
}

Source: policy_definitions/Audit-Disks-UnusedResourcesCostOptimization.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.