I have below terraform code which creates maintenance configuration it is only for one virtual machine. you can see in the below code.
provider "azurerm" {
features {}
}
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
version = "=0.4.0"
}
}
}
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
# resource "azurerm_maintenance_configuration" "example" {
# name = "example-mc"
# resource_group_name = azurerm_resource_group.example.name
# location = azurerm_resource_group.example.location
# scope = "InGuestPatch"
# tags = {
# Env = "prod"
# }
# }
resource "azapi_resource" "vm_maintenance" {
type = "Microsoft.Maintenance/maintenanceConfigurations@2021-09-01-preview"
name = "vm-mc"
parent_id = "/subscriptions/XXXX/resourceGroups/example-resources"
location = azurerm_resource_group.example.location
body = jsonencode({
properties = {
visibility = "Custom"
namespace = "Microsoft.Maintenance"
maintenanceScope = "InGuestPatch"
extensionProperties = {
"InGuestPatchMode" = "User"
}
maintenanceWindow = {
startDateTime = formatdate("YYYY-MM-DD 17:30", timestamp())
expirationDateTime = null
duration = "PT3H30M"
timeZone = "Eastern Standard Time"
recurEvery = "120Hour"
}
installPatches = {
linuxParameters = {
classificationsToInclude = ["Critical", "Security", "Other"]
packageNameMasksToExclude = null
packageNameMasksToInclude = null
}
windowsParameters = {
classificationsToInclude = ["Critical", "Security" , "UpdateRollup", "FeaturePack" , "ServicePack", "Definition" ,"Tools", "Updates" ]
kbNumbersToExclude = null
kbNumbersToInclude = null
}
rebootSetting = "RebootIfRequired"
}
}
})
}
resource "azapi_resource" "vm_maintenance_assignment" {
type = "Microsoft.Maintenance/configurationAssignments@2021-09-01-preview"
name = "vm--mca"
parent_id = "/subscriptions/XXX/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/test1"
location = "East US 2"
body = jsonencode({
properties = {
maintenanceConfigurationId = azapi_resource.vm_maintenance.id
}
})
}ype or paste code here
how do I assign it to multiple existing virtual machines? Please suggest fix