Control updates with Maintenance Configurations and the Azure CLI
Applies to: ✔️ Linux VMs ✔️ Windows VMs ✔️ Flexible scale sets ✔️ Uniform scale sets
Maintenance Configurations lets you decide when to apply platform updates to various Azure resources. This topic covers the Azure CLI options for Dedicated Hosts and Isolated VMs. For more about benefits of using Maintenance Configurations, its limitations, and other management options, see Managing platform updates with Maintenance Configurations.
Important
There are different scopes which support certain machine types and schedules, so please ensure you are selecting the right scope for your virtual machine.
Create a maintenance configuration
Use az maintenance configuration create to create a maintenance configuration. This example creates a maintenance configuration named myConfig scoped to the host.
az group create \
--location eastus \
--name myMaintenanceRG
az maintenance configuration create \
-g myMaintenanceRG \
--resource-name myConfig \
--maintenance-scope host\
--location eastus
Copy the configuration ID from the output to use later.
Using --maintenance-scope host ensures that the maintenance configuration is used for controlling updates to the host infrastructure.
If you try to create a configuration with the same name, but in a different location, you will get an error. Configuration names must be unique to your resource group.
You can query for available maintenance configurations using az maintenance configuration list.
az maintenance configuration list --query "[].{Name:name, ID:id}" -o table
Create a maintenance configuration with scheduled window
You can also declare a scheduled window when Azure will apply the updates on your resources. This example creates a maintenance configuration named myConfig with a scheduled window of 5 hours on the fourth Monday of every month. Once you create a scheduled window you no longer have to apply the updates manually.
az maintenance configuration create \
-g myMaintenanceRG \
--resource-name myConfig \
--maintenance-scope host \
--location eastus \
--maintenance-window-duration "05:00" \
--maintenance-window-recur-every "Month Fourth Monday" \
--maintenance-window-start-date-time "2020-12-30 08:00" \
--maintenance-window-time-zone "Pacific Standard Time"
Important
Maintenance duration must be 2 hours or longer.
Maintenance recurrence can be expressed as daily, weekly or monthly. Some examples are:
- daily- maintenance-window-recur-every: "Day" or "3Days"
- weekly- maintenance-window-recur-every: "3Weeks" or "Week Saturday,Sunday"
- monthly- maintenance-window-recur-every: "Month day23,day24" or "Month Last Sunday" or "Month Fourth Monday"
Assign the configuration
Use az maintenance assignment create to assign the configuration to your machine.
Isolated VM
Apply the configuration to a VM using the ID of the configuration. Specify --resource-type virtualMachines and supply the name of the VM for --resource-name, and the resource group for to the VM in --resource-group, and the location of the VM for --location.
az maintenance assignment create \
--resource-group myMaintenanceRG \
--location eastus \
--resource-name myVM \
--resource-type virtualMachines \
--provider-name Microsoft.Compute \
--configuration-assignment-name myConfig \
--maintenance-configuration-id "/subscriptions/1111abcd-1a11-1a2b-1a12-123456789abc/resourcegroups/myMaintenanceRG/providers/Microsoft.Maintenance/maintenanceConfigurations/myConfig"
Dedicated host
To apply a configuration to a dedicated host, you need to include --resource-type hosts, --resource-parent-name with the name of the host group, and --resource-parent-type hostGroups.
The parameter --resource-id is the ID of the host. You can use az-vm-host-get-instance-view to get the ID of your dedicated host.
az maintenance assignment create \
-g myDHResourceGroup \
--resource-name myHost \
--resource-type hosts \
--provider-name Microsoft.Compute \
--configuration-assignment-name myConfig \
--maintenance-configuration-id "/subscriptions/1111abcd-1a11-1a2b-1a12-123456789abc/resourcegroups/myDhResourceGroup/providers/Microsoft.Maintenance/maintenanceConfigurations/myConfig" \
-l eastus \
--resource-parent-name myHostGroup \
--resource-parent-type hostGroups
Check configuration
You can verify that the configuration was applied correctly, or check to see what configuration is currently applied using az maintenance assignment list.
Isolated VM
az maintenance assignment list \
--provider-name Microsoft.Compute \
--resource-group myMaintenanceRG \
--resource-name myVM \
--resource-type virtualMachines \
--query "[].{resource:resourceGroup, configName:name}" \
--output table
Dedicated host
az maintenance assignment list \
--resource-group myDHResourceGroup \
--resource-name myHost \
--resource-type hosts \
--provider-name Microsoft.Compute \
--resource-parent-name myHostGroup \
--resource-parent-type hostGroups
--query "[].{ResourceGroup:resourceGroup,configName:name}" \
-o table
Check for pending updates
Use az maintenance update list to see if there are pending updates. Update --subscription to be the ID for the subscription that contains the VM.
If there are no updates, the command will return an error message, which will contain the text: Resource not found...StatusCode: 404.
If there are updates, only one will be returned, even if there are multiple updates pending. The data for this update will be returned in an object:
[
{
"impactDurationInSec": 9,
"impactType": "Freeze",
"maintenanceScope": "Host",
"notBefore": "2020-03-03T07:23:04.905538+00:00",
"resourceId": "/subscriptions/9120c5ff-e78e-4bd0-b29f-75c19cadd078/resourcegroups/DemoRG/providers/Microsoft.Compute/hostGroups/demoHostGroup/hosts/myHost",
"status": "Pending"
}
]
Isolated VM
Check for pending updates for an isolated VM. In this example, the output is formatted as a table for readability.
az maintenance update list \
-g myMaintenanceRg \
--resource-name myVM \
--resource-type virtualMachines \
--provider-name Microsoft.Compute \
-o table
Dedicated host
To check for pending updates for a dedicated host. In this example, the output is formatted as a table for readability. Replace the values for the resources with your own.
az maintenance update list \
--subscription 1111abcd-1a11-1a2b-1a12-123456789abc \
-g myHostResourceGroup \
--resource-name myHost \
--resource-type hosts \
--provider-name Microsoft.Compute \
--resource-parentname myHostGroup \
--resource-parent-type hostGroups \
-o table
Apply updates
Use az maintenance apply update to apply pending updates. On success, this command will return JSON containing the details of the update. Apply update calls can take upto 2 hours to complete.
Isolated VM
Create a request to apply updates to an isolated VM.
az maintenance applyupdate create \
--subscription 1111abcd-1a11-1a2b-1a12-123456789abc \
--resource-group myMaintenanceRG \
--resource-name myVM \
--resource-type virtualMachines \
--provider-name Microsoft.Compute
Dedicated host
Apply updates to a dedicated host.
az maintenance applyupdate create \
--subscription 1111abcd-1a11-1a2b-1a12-123456789abc \
--resource-group myHostResourceGroup \
--resource-name myHost \
--resource-type hosts \
--provider-name Microsoft.Compute \
--resource-parent-name myHostGroup \
--resource-parent-type hostGroups
Check the status of applying updates
You can check on the progress of the updates using az maintenance applyupdate get.
You can use default as the update name to see results for the last update, or replace myUpdateName with the name of the update that was returned when you ran az maintenance applyupdate create.
Status : Completed
ResourceId : /subscriptions/12ae7457-4a34-465c-94c1-17c058c2bd25/resourcegroups/TestShantS/providers/Microsoft.Comp
ute/virtualMachines/DXT-test-04-iso
LastUpdateTime : 1/1/2020 12:00:00 AM
Id : /subscriptions/12ae7457-4a34-465c-94c1-17c058c2bd25/resourcegroups/TestShantS/providers/Microsoft.Comp
ute/virtualMachines/DXT-test-04-iso/providers/Microsoft.Maintenance/applyUpdates/default
Name : default
Type : Microsoft.Maintenance/applyUpdates
LastUpdateTime will be the time when the update got complete, either initiated by you or by the platform in case self-maintenance window was not used. If there has never been an update applied through maintenance control it will show default value.
Isolated VM
az maintenance applyupdate get \
--resource-group myMaintenanceRG \
--resource-name myVM \
--resource-type virtualMachines \
--provider-name Microsoft.Compute \
--apply-update-name default
Dedicated host
az maintenance applyupdate get \
--subscription 1111abcd-1a11-1a2b-1a12-123456789abc \
--resource-group myMaintenanceRG \
--resource-name myHost \
--resource-type hosts \
--provider-name Microsoft.Compute \
--resource-parent-name myHostGroup \
--resource-parent-type hostGroups \
--apply-update-name myUpdateName \
--query "{LastUpdate:lastUpdateTime, Name:name, ResourceGroup:resourceGroup, Status:status}" \
--output table
Delete a maintenance configuration
Use az maintenance configuration delete to delete a maintenance configuration. Deleting the configuration removes the maintenance control from the associated resources.
az maintenance configuration delete \
--subscription 1111abcd-1a11-1a2b-1a12-123456789abc \
-g myResourceGroup \
--resource-name myConfig
Next steps
To learn more, see Maintenance and updates.
Feedback
Submit and view feedback for