Bylaw

Gallery › Sovereignty › Azure built-in policies

[Preview]: IoT Hub Device Provisioning Service linked IoT Hub locations should use allowed locations

Converted Policy Audit Disabled Mode Indexed Version 1.0.0-preview Preview

Restrict the locations of IoT hubs linked to Azure IoT Hub Device Provisioning Service to approved regions to meet data residency and sovereignty requirements. This policy evaluates linked IoT Hub allocation destinations and does not evaluate the provisioning service's primary location.

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

Azure Policy JSONIoTDpsReplicaLocations_Audit.json · 64 lines
{
  "properties": {
    "displayName": "[Preview]: IoT Hub Device Provisioning Service linked IoT Hub locations should use allowed locations",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Restrict the locations of IoT hubs linked to Azure IoT Hub Device Provisioning Service to approved regions to meet data residency and sovereignty requirements. This policy evaluates linked IoT Hub allocation destinations and does not evaluate the provisioning service's primary location.",
    "metadata": {
      "version": "1.0.0-preview",
      "category": "Sovereignty",
      "preview": true
    },
    "version": "1.0.0-preview",
    "parameters": {
      "allowedReplicaLocations": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed replica locations",
          "description": "The list of locations where IoT hubs linked to Device Provisioning Service 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/provisioningServices"
          },
          {
            "count": {
              "field": "Microsoft.Devices/ProvisioningServices/iotHubs[*]",
              "where": {
                "value": "[replace(toLower(current('Microsoft.Devices/ProvisioningServices/iotHubs[*].location')), ' ', '')]",
                "notIn": "[parameters('allowedReplicaLocations')]"
              }
            },
            "greater": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/92af37fe-f8ff-4ebd-883d-2f80cd765f8f",
  "name": "92af37fe-f8ff-4ebd-883d-2f80cd765f8f"
}
Bylaw92af37fe-f8ff-4ebd-883d-2f80cd765f8f.bylaw.ps1 · 37 lines
# Converted from IoTDpsReplicaLocations_Audit.json by ConvertTo-Bylaw.
Policy '92af37fe-f8ff-4ebd-883d-2f80cd765f8f' {

    Properties @{
        DisplayName   = '[Preview]: IoT Hub Device Provisioning Service linked IoT Hub locations should use allowed locations'
        Description   = 'Restrict the locations of IoT hubs linked to Azure IoT Hub Device Provisioning Service to approved regions to meet data residency and sovereignty requirements. This policy evaluates linked IoT Hub allocation destinations and does not evaluate the provisioning service''s primary location.'
        Version       = '1.0.0-preview'
        Category      = 'Sovereignty'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        Mode          = 'Indexed'
    }

    Parameter AllowedReplicaLocations @{
        Type        = 'Array'
        DisplayName = 'Allowed replica locations'
        Description = 'The list of locations where IoT hubs linked to Device Provisioning Service 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/provisioningServices' {

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

    Effect (Param Effect)
}

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