Gallery › Lab Services › Azure built-in policies
Lab Services should enable all options for auto shutdown
Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0
This policy provides helps with cost management by enforcing all automatic shutdown options are enabled for a lab.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONEnforceAutoShutdown.json · 102 lines
{
"properties": {
"displayName": "Lab Services should enable all options for auto shutdown",
"description": "This policy provides helps with cost management by enforcing all automatic shutdown options are enabled for a lab.",
"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": {
"anyOf": [
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.LabServices/labs"
},
{
"field": "Microsoft.LabServices/labs/labPlanId",
"notEquals": "[parameters('excludeLabPlanId')]"
},
{
"anyOf": [
{
"field": "Microsoft.LabServices/labs/autoShutdownProfile.shutdownOnDisconnect",
"equals": "Disabled"
},
{
"field": "Microsoft.LabServices/labs/autoShutdownProfile.shutdownWhenNotConnected",
"equals": "Disabled"
},
{
"field": "Microsoft.LabServices/labs/autoShutdownProfile.shutdownOnIdle",
"equals": "None"
}
]
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.LabServices/labplans"
},
{
"anyOf": [
{
"field": "Microsoft.LabServices/labPlans/defaultAutoShutdownProfile.shutdownOnDisconnect",
"equals": "Disabled"
},
{
"field": "Microsoft.LabServices/labPlans/defaultAutoShutdownProfile.shutdownWhenNotConnected",
"equals": "Disabled"
},
{
"field": "Microsoft.LabServices/labPlans/defaultAutoShutdownProfile.shutdownOnIdle",
"equals": "None"
}
]
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.1.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/a6e9cf2d-7d76-440e-b795-8da246bd3aab",
"name": "a6e9cf2d-7d76-440e-b795-8da246bd3aab"
}Bylawa6e9cf2d-7d76-440e-b795-8da246bd3aab.bylaw.ps1 · 52 lines
# Converted from EnforceAutoShutdown.json by ConvertTo-Bylaw.
Policy 'a6e9cf2d-7d76-440e-b795-8da246bd3aab' {
Properties @{
DisplayName = 'Lab Services should enable all options for auto shutdown'
Description = 'This policy provides helps with cost management by enforcing all automatic shutdown options are enabled for a lab.'
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 * {
Require 'type, labPlanId, autoShutdownProfile.shutdownOnDisconnect and 2 more are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.LabServices/labs' -IfPresent
Field 'Microsoft.LabServices/labs/labPlanId' | Must -Be (Param ExcludeLabPlanId)
AllOf {
Field 'Microsoft.LabServices/labs/autoShutdownProfile.shutdownOnDisconnect' | Must -Not -Be 'Disabled' -IfPresent
Field 'Microsoft.LabServices/labs/autoShutdownProfile.shutdownWhenNotConnected' | Must -Not -Be 'Disabled' -IfPresent
Field 'Microsoft.LabServices/labs/autoShutdownProfile.shutdownOnIdle' | Must -Not -Be 'None' -IfPresent
}
}
}
Require 'type, defaultAutoShutdownProfile.shutdownOnDisconnect, defaultAutoShutdownProfile.shutdownWhenNotConnected and 1 more are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.LabServices/labplans' -IfPresent
AllOf {
Field 'Microsoft.LabServices/labPlans/defaultAutoShutdownProfile.shutdownOnDisconnect' | Must -Not -Be 'Disabled' -IfPresent
Field 'Microsoft.LabServices/labPlans/defaultAutoShutdownProfile.shutdownWhenNotConnected' | Must -Not -Be 'Disabled' -IfPresent
Field 'Microsoft.LabServices/labPlans/defaultAutoShutdownProfile.shutdownOnIdle' | Must -Not -Be 'None' -IfPresent
}
}
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/Lab Services/EnforceAutoShutdown.json in Azure/azure-policy, under the MIT licence.
Bylaw