Bylaw

Gallery › Compute › Azure built-in policies

[Deprecated]: Unattached disks should be encrypted

Converted Policy Audit Disabled Mode Indexed Version 1.0.0-deprecated Deprecated

This policy audits any unattached disk without encryption enabled.

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

Azure Policy JSONUnattachedDisk_Encryption_Audit.json · 62 lines
{
  "properties": {
    "displayName": "[Deprecated]: Unattached disks should be encrypted",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy audits any unattached disk without encryption enabled.",
    "metadata": {
      "version": "1.0.0-deprecated",
      "category": "Compute",
      "deprecated": true
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/disks"
          },
          {
            "field": "Microsoft.Compute/disks/diskState",
            "equals": "Unattached"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Compute/disks/encryptionSettingsCollection.enabled",
                "exists": "false"
              },
              {
                "field": "Microsoft.Compute/disks/encryptionSettingsCollection.enabled",
                "equals": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/2c89a2e5-7285-40fe-afe0-ae8654b92fb2",
  "name": "2c89a2e5-7285-40fe-afe0-ae8654b92fb2"
}
Bylaw2c89a2e5-7285-40fe-afe0-ae8654b92fb2.bylaw.ps1 · 38 lines
# Converted from UnattachedDisk_Encryption_Audit.json by ConvertTo-Bylaw.
Policy '2c89a2e5-7285-40fe-afe0-ae8654b92fb2' {

    Properties @{
        DisplayName   = '[Deprecated]: Unattached disks should be encrypted'
        Description   = 'This policy audits any unattached disk without encryption enabled.'
        Version       = '1.0.0-deprecated'
        Category      = 'Compute'
        Deprecated    = $true
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        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'
        }

        Require 'encryptionSettingsCollection.enabled exists' {
            Field encryptionSettingsCollection.enabled | Must -Exist
        }

        Require 'encryptionSettingsCollection.enabled is not false' {
            Field encryptionSettingsCollection.enabled | Must -Not -Be 'false' -IfPresent
        }
    }

    Effect (Param Effect)
}

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