Bylaw

Gallery › Storage › Azure built-in policies

Storage accounts should be limited by allowed SKUs

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0

Restrict the set of storage account SKUs that your organization can deploy.

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

Azure Policy JSONAllowedStorageSkus_Audit.json · 60 lines
{
  "properties": {
    "displayName": "Storage accounts should be limited by allowed SKUs",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Restrict the set of storage account SKUs that your organization can deploy.",
    "metadata": {
      "version": "1.1.0",
      "category": "Storage"
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the audit policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Deny"
      },
      "listOfAllowedSKUs": {
        "type": "Array",
        "metadata": {
          "description": "The list of SKUs that can be specified for storage accounts.",
          "displayName": "Allowed SKUs",
          "strongType": "StorageSKUs"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          },
          {
            "not": {
              "field": "Microsoft.Storage/storageAccounts/sku.name",
              "in": "[parameters('listOfAllowedSKUs')]"
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1",
  "name": "7433c107-6db4-4ad1-b57a-a76dce0154a1"
}
Bylaw7433c107-6db4-4ad1-b57a-a76dce0154a1.bylaw.ps1 · 34 lines
# Converted from AllowedStorageSkus_Audit.json by ConvertTo-Bylaw.
Policy '7433c107-6db4-4ad1-b57a-a76dce0154a1' {

    Properties @{
        DisplayName   = 'Storage accounts should be limited by allowed SKUs'
        Description   = 'Restrict the set of storage account SKUs that your organization can deploy.'
        Version       = '1.1.0'
        Category      = 'Storage'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Deny'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the audit policy'
    }
    Parameter ListOfAllowedSKUs @{
        Type        = 'Array'
        DisplayName = 'Allowed SKUs'
        Description = 'The list of SKUs that can be specified for storage accounts.'
        Metadata    = [ordered]@{ strongType = 'StorageSKUs' }
    }

    Resource 'Microsoft.Storage/storageAccounts' {

        Require 'sku.name is one of the ListOfAllowedSKUs parameter' {
            Field sku.name | Must -BeIn (Param ListOfAllowedSKUs)
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Storage/AllowedStorageSkus_Audit.json in Azure/azure-policy, under the MIT licence.