Gallery › Compute › Azure Community Policy
Only allow a certain VM platform image
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
This policy ensures that only UbuntuServer, Canonical is allowed from the image repository
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 69 lines
{
"name": "eb7bff80-fb1c-4245-9837-9036c30b4f50",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Only allow a certain VM platform image",
"description": "This policy ensures that only UbuntuServer, Canonical is allowed from the image repository",
"metadata": {
"version": "1.0.0",
"category": "Compute"
},
"mode": "All",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Deny, Audit or Disabled the execution of the Policy"
},
"allowedValues": [
"Deny",
"Audit",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"in": [
"Microsoft.Compute/disks",
"Microsoft.Compute/virtualMachines",
"Microsoft.Compute/VirtualMachineScaleSets"
]
},
{
"not": {
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"in": [
"Canonical"
]
},
{
"field": "Microsoft.Compute/imageOffer",
"in": [
"UbuntuServer"
]
},
{
"field": "Microsoft.Compute/imageSku",
"in": [
"14.04.2-LTS"
]
}
]
}
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylaweb7bff80-fb1c-4245-9837-9036c30b4f50.bylaw.ps1 · 39 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'eb7bff80-fb1c-4245-9837-9036c30b4f50' {
Properties @{
DisplayName = 'Only allow a certain VM platform image'
Description = 'This policy ensures that only UbuntuServer, Canonical is allowed from the image repository'
Version = '1.0.0'
Category = 'Compute'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource * {
When {
Field type | Must -BeIn @('Microsoft.Compute/disks', 'Microsoft.Compute/virtualMachines', 'Microsoft.Compute/VirtualMachineScaleSets')
}
Require 'imagePublisher is one of 1 value' {
Field 'Microsoft.Compute/imagePublisher' | Must -BeIn @('Canonical')
}
Require 'imageOffer is one of 1 value' {
Field 'Microsoft.Compute/imageOffer' | Must -BeIn @('UbuntuServer')
}
Require 'imageSku is one of 1 value' {
Field 'Microsoft.Compute/imageSku' | Must -BeIn @('14.04.2-LTS')
}
}
Effect (Param Effect)
}Source: policyDefinitions/Compute/only-allow-a-certain-vm-platform-image/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw