Gallery › Automation › Azure Community Policy
Deploy DSC Extension to Azure VM and Arc connected machines
Doesn't convert yet Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0
Deploys the DSC extension to and assigns configuration artifact from url location.
ConvertTo-Bylaw can't convert this policy yet:
- BYL6003 The converted file doesn't compile, which is a ConvertTo-Bylaw bug: BYL2003: Related resource type '[if(equals(tolower(field('Type')),'microsoft.compute/virtualmachines'),'Microsoft.Compute/virtualMachines/extensions','Microsoft.HybridCompute/machines/extensions')]' is not in the alias snapshot (/home/runner/work/PowerShell-Bylaw/PowerShell-Bylaw/src/Data/aliases.json). Check the spelling, refresh the snapshot with Update-BylawAliasCache, or use -AllowUnknownAlias.
Azure Policy JSONazurepolicy.json · 332 lines
{
"name": "c199fb0c-4bef-41f2-ba24-3b4847e54b25",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Deploy DSC Extension to Azure VM and Arc connected machines",
"description": "Deploys the DSC extension to and assigns configuration artifact from url location.",
"metadata": {
"category": "Automation",
"version": "1.0.0"
},
"mode": "Indexed",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"DeployIfNotExists",
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
},
"configurationUrl": {
"type": "String",
"metadata": {
"description": "URL for the configuration"
}
},
"configurationScript": {
"type": "String",
"metadata": {
"description": "Script for the configuration (e.g. ExampleDSC.zip)"
}
},
"configurationFunction": {
"type": "String",
"metadata": {
"description": "Configuration Function (e.g. ExampleDSC.ps1\\ExampleDSC)"
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "tags['dsc']",
"equals": "true"
},
{
"anyOf": [
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"anyOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"in": [
"esri",
"incredibuild",
"MicrosoftDynamicsAX",
"MicrosoftSharepoint",
"MicrosoftVisualStudio",
"MicrosoftWindowsDesktop",
"MicrosoftWindowsServerHPCPack"
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "MicrosoftWindowsServer"
},
{
"field": "Microsoft.Compute/imageSKU",
"notLike": "2008*"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "MicrosoftSQLServer"
},
{
"field": "Microsoft.Compute/imageOffer",
"notLike": "SQL2008*"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "microsoft-dsvm"
},
{
"field": "Microsoft.Compute/imageOffer",
"equals": "dsvm-windows"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "microsoft-ads"
},
{
"field": "Microsoft.Compute/imageOffer",
"in": [
"standard-data-science-vm",
"windows-data-science-vm"
]
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "batch"
},
{
"field": "Microsoft.Compute/imageOffer",
"equals": "rendering-windows2016"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "center-for-internet-security-inc"
},
{
"field": "Microsoft.Compute/imageOffer",
"like": "cis-windows-server-201*"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "pivotal"
},
{
"field": "Microsoft.Compute/imageOffer",
"like": "bosh-windows-server*"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "cloud-infrastructure-services"
},
{
"field": "Microsoft.Compute/imageOffer",
"like": "ad*"
}
]
},
{
"allOf": [
{
"anyOf": [
{
"field": "Microsoft.Compute/virtualMachines/osProfile.windowsConfiguration",
"exists": "true"
},
{
"field": "Microsoft.Compute/virtualMachines/storageProfile.osDisk.osType",
"like": "Windows*"
}
]
},
{
"anyOf": [
{
"field": "Microsoft.Compute/imageSKU",
"exists": "false"
},
{
"allOf": [
{
"field": "Microsoft.Compute/imageSKU",
"notLike": "2008*"
},
{
"field": "Microsoft.Compute/imageOffer",
"notLike": "SQL2008*"
}
]
}
]
}
]
}
]
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.HybridCompute/machines"
},
{
"field": "Microsoft.HybridCompute/imageOffer",
"like": "windows*"
}
]
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"type": "[if(equals(tolower(field('Type')),'microsoft.compute/virtualmachines'),'Microsoft.Compute/virtualMachines/extensions','Microsoft.HybridCompute/machines/extensions')]",
"name": "DSC",
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"configurationUrl": {
"value": "[parameters('configurationUrl')]"
},
"configurationScript": {
"value": "[parameters('configurationScript')]"
},
"configurationFunction": {
"value": "[parameters('configurationFunction')]"
},
"machineName": {
"value": "[field('name')]"
},
"location": {
"value": "[field('location')]"
},
"type": {
"value": "[field('type')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"configurationUrl": {
"type": "String"
},
"configurationScript": {
"type": "String"
},
"configurationFunction": {
"type": "String"
},
"machineName": {
"type": "String"
},
"location": {
"type": "string"
},
"type": {
"type": "string"
}
},
"resources": [
{
"condition": "[equals(toLower(parameters('type')), toLower('Microsoft.Compute/virtualMachines'))]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('machineName'),'/DSC')]",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.80",
"autoUpgradeMinorVersion": true,
"settings": {
"configuration": {
"url": "[parameters('configurationUrl')]",
"script": "[parameters('configurationScript')]",
"function": "[parameters('configurationFunction')]"
}
}
}
},
{
"condition": "[equals(toLower(parameters('type')), toLower('microsoft.hybridcompute/machines'))]",
"type": "Microsoft.HybridCompute/machines/extensions",
"name": "[concat(parameters('machineName'),'/DSC')]",
"apiVersion": "2019-12-12",
"location": "[parameters('location')]",
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.80",
"autoUpgradeMinorVersion": true,
"settings": {
"configuration": {
"url": "[parameters('configurationUrl')]",
"script": "[parameters('configurationScript')]",
"function": "[parameters('configurationFunction')]"
}
}
}
}
]
}
}
}
}
}
}
}
}Source: policyDefinitions/Automation/deploy-dsc-extension-to-azure-vm-and-arc-connected-machines/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw