Bylaw

Gallery › Sovereignty › Azure built-in policies

[Preview]: Azure IoT Hub disaster recovery secondary locations should use allowed locations

Converted Policy Audit Disabled Mode Indexed Version 1.0.0-preview Preview

Audit Azure IoT hubs when their Microsoft-managed disaster recovery secondary location is outside the list of allowed locations. This policy does not evaluate the hub's primary location.

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

Azure Policy JSONIoTHubReplicaLocations_Audit.json · 72 lines
{
  "properties": {
    "displayName": "[Preview]: Azure IoT Hub disaster recovery secondary locations should use allowed locations",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Audit Azure IoT hubs when their Microsoft-managed disaster recovery secondary location is outside the list of allowed locations. This policy does not evaluate the hub's primary location.",
    "metadata": {
      "version": "1.0.0-preview",
      "category": "Sovereignty",
      "preview": true
    },
    "version": "1.0.0-preview",
    "parameters": {
      "allowedSecondaryLocations": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed disaster recovery secondary locations",
          "description": "The list of locations where Azure IoT Hub disaster recovery secondaries are allowed.",
          "strongType": "location"
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Devices/IotHubs"
          },
          {
            "count": {
              "field": "Microsoft.Devices/IotHubs/locations[*]",
              "where": {
                "allOf": [
                  {
                    "value": "[toLower(current('Microsoft.Devices/IotHubs/locations[*].role'))]",
                    "equals": "secondary"
                  },
                  {
                    "value": "[replace(toLower(current('Microsoft.Devices/IotHubs/locations[*].location')), ' ', '')]",
                    "notIn": "[parameters('allowedSecondaryLocations')]"
                  }
                ]
              }
            },
            "greater": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/93fc07ef-f4b9-418a-9190-6e2628e72856",
  "name": "93fc07ef-f4b9-418a-9190-6e2628e72856"
}
Bylaw93fc07ef-f4b9-418a-9190-6e2628e72856.bylaw.ps1 · 38 lines
# Converted from IoTHubReplicaLocations_Audit.json by ConvertTo-Bylaw.
Policy '93fc07ef-f4b9-418a-9190-6e2628e72856' {

    Properties @{
        DisplayName   = '[Preview]: Azure IoT Hub disaster recovery secondary locations should use allowed locations'
        Description   = 'Audit Azure IoT hubs when their Microsoft-managed disaster recovery secondary location is outside the list of allowed locations. This policy does not evaluate the hub''s primary location.'
        Version       = '1.0.0-preview'
        Category      = 'Sovereignty'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        Mode          = 'Indexed'
    }

    Parameter AllowedSecondaryLocations @{
        Type        = 'Array'
        DisplayName = 'Allowed disaster recovery secondary locations'
        Description = 'The list of locations where Azure IoT Hub disaster recovery secondaries are allowed.'
        Metadata    = [ordered]@{ strongType = 'location' }
    }
    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.Devices/IotHubs' {

        Require 'locations is as required' {
            Count 'locations[*]' -Where {
                Arm '[toLower(current(''Microsoft.Devices/IotHubs/locations[*].role''))]' | Must -Be 'secondary'
                Arm '[replace(toLower(current(''Microsoft.Devices/IotHubs/locations[*].location'')), '' '', '''')]' | Must -Not -BeIn (Param AllowedSecondaryLocations)
            } | Must -Be 0
        }
    }

    Effect (Param Effect)
}

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