Bicep deployment of maintenance configuration assigment for scope Resource

bombbe 1,466 Reputation points
2025-10-15T08:37:51.0633333+00:00

Hi,

I have seen few post about Bicep deployment of maintenance configuration assigment but they have always been for dynamic scopes. I have created maintenance Configurations with maintenanceScope: 'Resource' for our VPN gateways. Deployment of that is went just fine.

Now I'm trying to assign single VPN to that configuration with the vpn resouceId but the deployment always seems to be failing and struglin to find right format.

This is my current Main bicep

module maintenance_assignments 'maintenance_assignment.bicep' = [for testing in assignment_test: {
  scope: subscription()
  name: '${assignment.mCName}'
  params: {
    maintenanceConfigurationId: assignment.maintenanceConfigurationId
    resourceId: assignment.resourceId
  }
}]


This is my module currently module

targetScope = 'subscription'

param resourceId string
param maintenanceConfigurationId string

resource configurationAssignment 'Microsoft.Maintenance/configurationAssignments@2023-04-01' = {
  name: last(split(resourceId, '/'))
  properties: {
    maintenanceConfigurationId: maintenanceConfigurationId
    resourceId: resourceId
  }
}

I have tried with targetScope = 'subscription' and targetScope = 'resoucegroup' and with and without having "location" parameter and mix of these but it always failing with refering to subscription or resouce group.

Provided combination of resource type Microsoft.Resource/subscriptions and maintenance configuration scope Resource aren't supported. Only following resource types are supported for scope Resource: Microsoft.ContainerService/managedClusters,Microsoft.ServiceFabric/managedClusters,Microsoft.Network/vpnGateways,Microsoft.Network/expressRouteGateways,Microsoft.Network/virtualnetworkgateways,Microsoft.Network/applicationGateways,Microsoft.Network/azureFirewalls,Microsoft.Network/virtualHubs,Microsoft.Network/bastionHosts,Microsoft.Network/networkVirtualAppliances,Microsoft.Network/p2sVpnGateways,Microsoft.Web/hostingEnvironments,Configuration assignment ResourceId must be empty or equal to the Subscription/Resource Group id for Subscription/Resource Group level assignment.,Given Maintenance Subscope value (NetworkGatewayMaintenance) is not compatible with the resource type Microsoft.Resource/subscriptions.,Cross Region Config Assignment is not allowed for NetworkGatewayMaintenance resources

I would want to just assignt that one vpn to that maintenanceConfiguration but note sure if that is possible or am I just doing something wrong here?

Azure Update Manager
Azure Update Manager
An Azure service to centrally manages updates and compliance at scale.
{count} votes

Answer accepted by question author
  1. Alex Burlachenko 18,570 Reputation points Volunteer Moderator
    2025-10-15T10:48:45.8366667+00:00

    Hi bombbe,

    the error message is telling you everything. you are trying to assign a maintenance configuration with scope 'resource' at the subscription level, but that is not allowed. the deployment scope and the assignment scope are fighting each other.

    your maintenance configuration is scoped to a single 'resource', like a vpn gateway. therefore, the configurationAssignment resource itself must be deployed directly onto that specific vpn gateway resource, not at the subscription or resource group level.

    you cannot use a subscription scoped module for this. you need to deploy the assignment as a resource within the scope of the vpn gateway itself.

    remove the module that has targetScope = 'subscription'. instead, in your main bicep file, you need to create the configurationAssignment resource inside the same resource group as your vpn gateway, and you must use the vpn gateway's resource id as the parent scope.

    if your vpn gateway is defined in the same bicep file, it would look like this.

    resource vpnGateway 'Microsoft.Network/vpnGateways@2023-09-01' = {
    name: 'myVpnGateway'
    location: location
    ...other properties...
    }
    resource maintenanceAssignment 'Microsoft.Maintenance/configurationAssignments@2023-04-01' = {
    parent: vpnGateway
    name: 'myAssignment'
    properties: {
    maintenanceConfigurationId: maintenanceConfigurationId
    }
    }
    

    see the parent: vpnGateway line? that is the key. it deploys the assignment as a child resource of the vpn gateway, which is exactly what the 'resource' maintenance scope requires.

    if your vpn gateway is in a different module or already exists, you need to use an existing resource reference to get its scope.

    this concept of deploying a resource as a child of another is a fundamental bicep pattern for resource specific configurations.

    you must deploy your configuration assignment as a child resource of the specific vpn gateway, not at the subscription level. the parent property is your solution.

    regards,

    Alex

    and "yes" if you would follow me at Q&A - personaly thx.
    P.S. If my answer help to you, please Accept my answer
    

    https://ctrlaltdel.blog/


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.