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