Your understanding is correct: Azure Policy is not designed for managing scheduled VM updates. Instead, Azure Update Manager is the appropriate tool for this scenario.
You might want to consider the following approach:
- Scheduling Weekly VM Updates You should use Update Manager's Maintenance Configuration to schedule weekly updates. Maintenance configurations allow you to specify:
- The frequency of updates (e.g., weekly).
- The time window for updates.
- The specific VMs or VM groups to include in the maintenance scope.
Steps:
- Navigate to Azure Update Manager in the Azure portal.
- Create a Maintenance Configuration with a weekly schedule and specify the time.
- Assign this configuration to the target VMs or VM groups.
- Handling Update Failures Disabling auto-update for a VM after an update failure can be handled indirectly by scripting and automation. Azure Policy itself cannot dynamically disable scheduled updates based on the success or failure of previous updates. However, you can achieve this with Azure Automation, Runbooks, and Logic Apps. Here's how:
- Monitor Update Status: Use Azure Update Manager's built-in reporting to track update failures. Alternatively, enable Azure Monitor or Log Analytics to capture update statuses.
- Automate Response to Failures:
Create an Azure Automation Runbook or Logic App to:
- Check for VMs with update failures using logs.
- Modify or remove the maintenance configuration for the affected VMs to disable auto-updates.
- Integrate with Alerts: Set up an alert in Azure Monitor to trigger the automation process when an update failure is detected.
For example:
- Log Update Failures:
- Use Update Manager logs in Log Analytics to monitor the
OperationName
andResultType
fields for update failures.
- Use Update Manager logs in Log Analytics to monitor the
- Trigger Automation:
- Use an alert in Azure Monitor to invoke a Runbook or Logic App.
- Runbook Example:
$failedVMs = Get-LogAnalyticsQueryResult -WorkspaceId <LogAnalyticsWorkspaceId> -Query " AzureDiagnostics | where OperationName == 'UpdateDeployment' and ResultType == 'Failed' | distinct Resource " foreach ($vm in $failedVMs) { Remove-AzAutomationScheduledRunbook -AutomationAccountName "UpdateAccount" -ResourceGroupName "MyResourceGroup" -RunbookName "WeeklyUpdate" -Target $vm Write-Output "Disabled auto-update for VM: $($vm.Resource)" }
- Re-enable Updates Manually:
- Investigate the failure, resolve the issue, and reassign the VM to the maintenance configuration.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin