Gallery › Lab Services › Azure built-in policies
Lab Services should restrict allowed virtual machine SKU sizes
Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0
This policy enables you to restrict certain Compute VM SKUs for labs managed through Lab Services. This will restrict certain virtual machine sizes.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONListAllowedSkuNames.json · 113 lines
{
"properties": {
"displayName": "Lab Services should restrict allowed virtual machine SKU sizes",
"description": "This policy enables you to restrict certain Compute VM SKUs for labs managed through Lab Services. This will restrict certain virtual machine sizes.",
"mode": "Indexed",
"policyType": "BuiltIn",
"metadata": {
"version": "1.1.0",
"category": "Lab Services"
},
"version": "1.1.0",
"parameters": {
"allowedSkus": {
"type": "Array",
"metadata": {
"displayName": "Allowed SKU names",
"description": "Select allowed SKU names from list",
"portalReview": true
},
"defaultValue": [
"Standard_Fsv2_2_4GB_64_S_SSD",
"Standard_Fsv2_2_4GB_128_S_SSD",
"Classic_Fsv2_2_4GB_128_S_SSD",
"Classic_Fsv2_4_8GB_128_S_SSD",
"Classic_Fsv2_8_16GB_128_S_SSD",
"Standard_Dsv4_2_8GB_128_S_SSD",
"Standard_Dsv4_4_16GB_128_S_SSD",
"Standard_Dsv4_4_16GB_128_P_SSD",
"Standard_Dsv4_8_32GB_128_S_SSD",
"Standard_Dsv4_8_32GB_128_P_SSD",
"Classic_Dsv4_4_16GB_128_P_SSD",
"Classic_Dsv4_8_32GB_128_P_SSD",
"Classic_NVv4_8_28GB_128_S_SSD",
"Classic_NVv4_16_56GB_128_S_SSD",
"Standard_Esv4_4_32GB_128_S_SSD",
"Standard_Esv4_4_32GB_128_P_SSD"
],
"allowedValues": [
"Standard_Fsv2_2_4GB_64_S_SSD",
"Standard_Fsv2_2_4GB_128_S_SSD",
"Classic_Fsv2_2_4GB_128_S_SSD",
"Basic",
"Classic_Fsv2_4_8GB_128_S_SSD",
"Standard",
"Classic_Fsv2_8_16GB_128_S_SSD",
"Large",
"Standard_Dsv4_2_8GB_128_S_SSD",
"Standard_Dsv4_4_16GB_128_S_SSD",
"Standard_Dsv4_4_16GB_128_P_SSD",
"Standard_Dsv4_8_32GB_128_S_SSD",
"Standard_Dsv4_8_32GB_128_P_SSD",
"Classic_Dsv4_4_16GB_128_P_SSD",
"Virtualization",
"Classic_Dsv4_8_32GB_128_P_SSD",
"Performance",
"Classic_NVv4_8_28GB_128_S_SSD",
"SmallGPUVisualization",
"Classic_NVv4_16_56GB_128_S_SSD",
"MediumGPUVisualization",
"Standard_Esv4_4_32GB_128_S_SSD",
"Standard_Esv4_4_32GB_128_P_SSD"
]
},
"excludeLabPlanId": {
"type": "String",
"metadata": {
"displayName": "Lab Plan Id to exclude",
"description": "Optionally enter the lab Plan Id to exclude for this policy."
},
"defaultValue": ""
},
"effect": {
"type": "String",
"defaultValue": "Audit",
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.LabServices/labs"
},
{
"field": "Microsoft.LabServices/labs/labPlanId",
"notEquals": "[parameters('excludeLabPlanId')]"
},
{
"field": "Microsoft.LabServices/labs/virtualMachineProfile.sku.name",
"notIn": "[parameters('allowedSkus')]"
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.1.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/3e13d504-9083-4912-b935-39a085db2249",
"name": "3e13d504-9083-4912-b935-39a085db2249"
}Bylaw3e13d504-9083-4912-b935-39a085db2249.bylaw.ps1 · 45 lines
# Converted from ListAllowedSkuNames.json by ConvertTo-Bylaw.
Policy '3e13d504-9083-4912-b935-39a085db2249' {
Properties @{
DisplayName = 'Lab Services should restrict allowed virtual machine SKU sizes'
Description = 'This policy enables you to restrict certain Compute VM SKUs for labs managed through Lab Services. This will restrict certain virtual machine sizes.'
Version = '1.1.0'
Category = 'Lab Services'
PolicyVersion = '1.1.0'
Mode = 'Indexed'
}
Parameter AllowedSkus @{
Type = 'Array'
AllowedValues = @('Standard_Fsv2_2_4GB_64_S_SSD', 'Standard_Fsv2_2_4GB_128_S_SSD', 'Classic_Fsv2_2_4GB_128_S_SSD', 'Basic', 'Classic_Fsv2_4_8GB_128_S_SSD', 'Standard', 'Classic_Fsv2_8_16GB_128_S_SSD', 'Large', 'Standard_Dsv4_2_8GB_128_S_SSD', 'Standard_Dsv4_4_16GB_128_S_SSD', 'Standard_Dsv4_4_16GB_128_P_SSD', 'Standard_Dsv4_8_32GB_128_S_SSD', 'Standard_Dsv4_8_32GB_128_P_SSD', 'Classic_Dsv4_4_16GB_128_P_SSD', 'Virtualization', 'Classic_Dsv4_8_32GB_128_P_SSD', 'Performance', 'Classic_NVv4_8_28GB_128_S_SSD', 'SmallGPUVisualization', 'Classic_NVv4_16_56GB_128_S_SSD', 'MediumGPUVisualization', 'Standard_Esv4_4_32GB_128_S_SSD', 'Standard_Esv4_4_32GB_128_P_SSD')
Default = @('Standard_Fsv2_2_4GB_64_S_SSD', 'Standard_Fsv2_2_4GB_128_S_SSD', 'Classic_Fsv2_2_4GB_128_S_SSD', 'Classic_Fsv2_4_8GB_128_S_SSD', 'Classic_Fsv2_8_16GB_128_S_SSD', 'Standard_Dsv4_2_8GB_128_S_SSD', 'Standard_Dsv4_4_16GB_128_S_SSD', 'Standard_Dsv4_4_16GB_128_P_SSD', 'Standard_Dsv4_8_32GB_128_S_SSD', 'Standard_Dsv4_8_32GB_128_P_SSD', 'Classic_Dsv4_4_16GB_128_P_SSD', 'Classic_Dsv4_8_32GB_128_P_SSD', 'Classic_NVv4_8_28GB_128_S_SSD', 'Classic_NVv4_16_56GB_128_S_SSD', 'Standard_Esv4_4_32GB_128_S_SSD', 'Standard_Esv4_4_32GB_128_P_SSD')
DisplayName = 'Allowed SKU names'
Description = 'Select allowed SKU names from list'
Metadata = [ordered]@{ portalReview = $true }
}
Parameter ExcludeLabPlanId @{
Default = ''
DisplayName = 'Lab Plan Id to exclude'
Description = 'Optionally enter the lab Plan Id to exclude for this policy.'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource 'Microsoft.LabServices/labs' {
When {
Field labPlanId | Must -Not -Be (Param ExcludeLabPlanId)
}
Require 'virtualMachineProfile.sku.name is one of the AllowedSkus parameter' {
Field virtualMachineProfile.sku.name | Must -BeIn (Param AllowedSkus)
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/Lab Services/ListAllowedSkuNames.json in Azure/azure-policy, under the MIT licence.
Bylaw