Is there a way to use New-AzMaintenanceConfiguration to also create a dynamic scope?

381 Views Asked by At

I want to programmatically create Maintenance Configurations using the new Azure Update Manager. To do this, I am utilizing the Az.Maintenance module, and specifically the New-AzMaintenanceConfiguration cmdlet. However, in the official documentation, I can't find any switch used to create a dynamic scope for assigning machines to the maintenance configuration.

I currently have no approach to this problem and would appreciate any ideas or help.

2

There are 2 best solutions below

0
CUiD8pdQJh On BEST ANSWER

Okay, I found the solution: The New-AzConfigurationAssignment cmdlet fits perfectly.

0
Jayendran On

It looks like New-AzConfigurationAssignment can only able to create the assignments within subscriptions.

The design of dynamic scope assignment is a little different as it creates resources at the subscription level and not at any RG level. So the resource id will look like

subscriptions/xxxxx/providers/Microsoft.Maintenance/configurationAssignments/DynamicAssignment1

Currently, the only way to create this using REST API (management)

Lets assume the maintaince configuration is at SubA, and you have to create the dynamic assignment by including SubB and SubC, then you have to follow below


PUT https://management.azure.com/subscriptions/xxxxx/providers/Microsoft.Maintenance/configurationAssignments/DynamicAssignment_SubB?api-version=2023-04-01"


{
    "location": "",
    "properties": {
        "maintenanceConfigurationId": "/subscriptions/yyyy/resourceGroups/maintenance-config-rg/providers/Microsoft.Maintenance/maintenanceConfigurations/mgconfig01_SubA"
    }
}

PUT https://management.azure.com/subscriptions/zzzz/providers/Microsoft.Maintenance/configurationAssignments/DynamicAssignment_SubC?api-version=2023-04-01"


{
    "location": "",
    "properties": {
        "maintenanceConfigurationId": "/subscriptions/yyyy/resourceGroups/maintenance-config-rg/providers/Microsoft.Maintenance/maintenanceConfigurations/mgconfig01_SubA"
    }
}



If you are comfortable with powershell, here its a good script that can help you to understand the flow


I also raised a feature request on azure-powershell github