Gallery › Lab Services › Azure built-in policies
Lab Services should not allow template virtual machines for labs
Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0
This policy prevents creation and customization of a template virtual machines for labs managed through Lab Services.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONTemplateLabsNotAllowed.json · 62 lines
{
"properties": {
"displayName": "Lab Services should not allow template virtual machines for labs",
"description": "This policy prevents creation and customization of a template virtual machines for labs managed through Lab Services.",
"mode": "Indexed",
"policyType": "BuiltIn",
"metadata": {
"version": "1.1.0",
"category": "Lab Services"
},
"version": "1.1.0",
"parameters": {
"effect": {
"type": "String",
"defaultValue": "Audit",
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
}
},
"excludeLabPlanId": {
"type": "String",
"metadata": {
"displayName": "Lab Plan Id to exclude",
"description": "Optionally enter the lab Plan Id to exclude for this policy assignment."
},
"defaultValue": ""
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.LabServices/labs"
},
{
"field": "Microsoft.LabServices/labs/labPlanId",
"notEquals": "[parameters('excludeLabPlanId')]"
},
{
"field": "Microsoft.LabServices/labs/virtualMachineProfile.createOption",
"equals": "TemplateVM"
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.1.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/e8a5a3eb-1ab6-4657-a701-7ae432cf14e1",
"name": "e8a5a3eb-1ab6-4657-a701-7ae432cf14e1"
}Bylawe8a5a3eb-1ab6-4657-a701-7ae432cf14e1.bylaw.ps1 · 37 lines
# Converted from TemplateLabsNotAllowed.json by ConvertTo-Bylaw.
Policy 'e8a5a3eb-1ab6-4657-a701-7ae432cf14e1' {
Properties @{
DisplayName = 'Lab Services should not allow template virtual machines for labs'
Description = 'This policy prevents creation and customization of a template virtual machines for labs managed through Lab Services.'
Version = '1.1.0'
Category = 'Lab Services'
PolicyVersion = '1.1.0'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter ExcludeLabPlanId @{
Default = ''
DisplayName = 'Lab Plan Id to exclude'
Description = 'Optionally enter the lab Plan Id to exclude for this policy assignment.'
}
Resource 'Microsoft.LabServices/labs' {
When {
Field labPlanId | Must -Not -Be (Param ExcludeLabPlanId)
}
Require 'virtualMachineProfile.createOption is not TemplateVM' {
Field virtualMachineProfile.createOption | Must -Not -Be 'TemplateVM' -IfPresent
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/Lab Services/TemplateLabsNotAllowed.json in Azure/azure-policy, under the MIT licence.
Bylaw