Bylaw

Gallery › Sovereignty › Azure built-in policies

[Preview]: Restrict resource types to Azure services supported in Azure Local

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0-preview Preview

Restrict the use of Azure services to those that run on Azure Local or have a supported migration path to Azure Local.

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

Azure Policy JSONRestrictToAzureLocalSupportedServices_Audit.json · 88 lines
{
  "properties": {
    "displayName": "[Preview]: Restrict resource types to Azure services supported in Azure Local",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Restrict the use of Azure services to those that run on Azure Local or have a supported migration path to Azure Local.",
    "metadata": {
      "version": "1.1.0-preview",
      "category": "Sovereignty",
      "preview": true
    },
    "version": "1.1.0-preview",
    "parameters": {
      "listOfResourceTypesSupportedInAzureLocal": {
        "type": "Array",
        "defaultValue": [
          "Microsoft.AzureArcData/*",
          "Microsoft.AzureStackHCI/*",
          "Microsoft.Compute/disks",
          "Microsoft.Compute/virtualMachines",
          "Microsoft.Compute/virtualMachines/*",
          "Microsoft.ContainerRegistry/registries",
          "Microsoft.ContainerRegistry/registries/*",
          "Microsoft.ContainerService/managedClusters",
          "Microsoft.ContainerService/managedClusters/*",
          "Microsoft.ExtendedLocation/customLocations",
          "Microsoft.HybridCompute/machines",
          "Microsoft.HybridCompute/machines/*",
          "Microsoft.HybridContainerService/*",
          "Microsoft.KeyVault/vaults",
          "Microsoft.KeyVault/vaults/*",
          "Microsoft.Kubernetes/connectedClusters",
          "Microsoft.Kubernetes/connectedClusters/*",
          "Microsoft.Network/loadBalancers",
          "Microsoft.Network/natGateways",
          "Microsoft.Network/networkInterfaces",
          "Microsoft.Network/networkSecurityGroups",
          "Microsoft.Network/networkSecurityGroups/*",
          "Microsoft.Network/publicIPAddresses",
          "Microsoft.Sql/managedInstances",
          "Microsoft.Sql/managedInstances/*",
          "Microsoft.Sql/servers",
          "Microsoft.Sql/servers/*"
        ],
        "metadata": {
          "description": "The list of Azure resource types that run on Azure Local or have a supported migration path to Azure Local, including the Azure Arc resource types that Azure Local projects into Azure.",
          "displayName": "Azure Local supported services",
          "strongType": "resourceTypes"
        }
      },
      "effect": {
        "type": "String",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "count": {
          "value": "[parameters('listOfResourceTypesSupportedInAzureLocal')]",
          "name": "allowedType",
          "where": {
            "value": "[field('type')]",
            "like": "[current('allowedType')]"
          }
        },
        "equals": 0
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0-PREVIEW",
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/9d35b50d-a1a5-4d67-a7ab-5115442bbfbb",
  "name": "9d35b50d-a1a5-4d67-a7ab-5115442bbfbb"
}
Bylaw9d35b50d-a1a5-4d67-a7ab-5115442bbfbb.bylaw.ps1 · 38 lines
# Converted from RestrictToAzureLocalSupportedServices_Audit.json by ConvertTo-Bylaw.
Policy '9d35b50d-a1a5-4d67-a7ab-5115442bbfbb' {

    Properties @{
        DisplayName   = '[Preview]: Restrict resource types to Azure services supported in Azure Local'
        Description   = 'Restrict the use of Azure services to those that run on Azure Local or have a supported migration path to Azure Local.'
        Version       = '1.1.0-preview'
        Category      = 'Sovereignty'
        Preview       = $true
        PolicyVersion = '1.1.0-preview'
        Mode          = 'Indexed'
    }

    Parameter ListOfResourceTypesSupportedInAzureLocal @{
        Type        = 'Array'
        Default     = @('Microsoft.AzureArcData/*', 'Microsoft.AzureStackHCI/*', 'Microsoft.Compute/disks', 'Microsoft.Compute/virtualMachines', 'Microsoft.Compute/virtualMachines/*', 'Microsoft.ContainerRegistry/registries', 'Microsoft.ContainerRegistry/registries/*', 'Microsoft.ContainerService/managedClusters', 'Microsoft.ContainerService/managedClusters/*', 'Microsoft.ExtendedLocation/customLocations', 'Microsoft.HybridCompute/machines', 'Microsoft.HybridCompute/machines/*', 'Microsoft.HybridContainerService/*', 'Microsoft.KeyVault/vaults', 'Microsoft.KeyVault/vaults/*', 'Microsoft.Kubernetes/connectedClusters', 'Microsoft.Kubernetes/connectedClusters/*', 'Microsoft.Network/loadBalancers', 'Microsoft.Network/natGateways', 'Microsoft.Network/networkInterfaces', 'Microsoft.Network/networkSecurityGroups', 'Microsoft.Network/networkSecurityGroups/*', 'Microsoft.Network/publicIPAddresses', 'Microsoft.Sql/managedInstances', 'Microsoft.Sql/managedInstances/*', 'Microsoft.Sql/servers', 'Microsoft.Sql/servers/*')
        DisplayName = 'Azure Local supported services'
        Description = 'The list of Azure resource types that run on Azure Local or have a supported migration path to Azure Local, including the Azure Arc resource types that Azure Local projects into Azure.'
        Metadata    = [ordered]@{ strongType = 'resourceTypes' }
    }
    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource * {

        Require 'type is as required' {
            Count -Value (Param ListOfResourceTypesSupportedInAzureLocal) -Name allowedType -Where {
                Arm '[field(''type'')]' | Must -BeLike (Current allowedType)
            } | Must -Not -Be 0
        }
    }

    Effect (Param Effect)
}

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