Unable to delete subnet in vnet due to AppServiceLink that cannot be removed

Scott McKendry 0 Reputation points
2024-03-19T19:14:34.42+00:00

I deployed an App Service Plan via bicep then attempted to deploy a function app on this ASP and associate it with a subnet (also created via bicep).

Unfortunately, the deployment failed because the function app name was already in use in some other subscription (AFAIK these must be globally unique, my mistake).

Following this, I deleted the ASP intending to redeploy the resources with a different naming convention.

But not I can't delete the subnet, because it's still linked to the now-deleted ASP. When trying to delete the subnet it the portal, I get the following

Failed to delete subnet '[subnet name]'. Error: Subnet [subnet name] is in use by [resource group]-prod/providers/Microsoft.Network/virtualNetworks/[vnet name]/subnets/[subnet name]/prod/serviceAssociationLinks/AppServiceLink'>[vnet name]/[subnet name]/AppServiceLink and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.

Appreciate any help I can get with resolving this.

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,118 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,765 questions
{count} votes

1 answer

Sort by: Most helpful
  1. GitaraniSharma-MSFT 46,751 Reputation points Microsoft Employee
    2024-03-21T13:37:33.3533333+00:00

    Hello @Scott McKendry ,

    Welcome to Microsoft Q&A Platform. Thank you for reaching out & hope you are doing well.

    I understand that you are unable to delete a Virtual network due to error related to AppServiceLink.

    Could you please confirm if you had a Vnet integration between the Vnet and a Web App and it was disconnected properly?

    When you have VNet Integration between a subnet and a Web App (part of App Service Plan), in the backend a link is automatically created (AppServiceLink) and a default delegation of Microsoft.Web/serverFarm happens on the specified subnet and if you delete the Web App/App Service Plan or set subnet delegation to none without disconnecting the VNet integration first, the link and delegation gets stuck in the backend. This results in AppServiceLink error which cannot be removed.

    We have a workaround which you can try to resolve this issue (may or may not work, depending on the situation):

    If you have already deleted the Web App, follow steps 1 to 5. If the Web App hasn't been deleted yet, follow steps 3 to 5. In your case since you've already deleted the Web app, please follow all the below steps.

    1. Recreate the App Service Plan that you had (the one you used for VNet Integration) with the exact same name as before in the exact same region as the vnet.
    2. Recreate the Web App (name of web app does not matter, it is important only for the App Service Plan)
    3. Recreate the VNet Integration from Web App > Networking Blade > New VNet Integration and select the specific subnet
    4. Properly remove the VNet Integration by hitting “Disconnect” in the Web App > Networking > VNet Integration.
    5. Now try and delete the subnet/vnet or set the Subnet Delegation to "none"

    Refer: https://learn.microsoft.com/en-us/azure/virtual-network/manage-subnet-delegation?tabs=manage-subnet-delegation-portal#remove-subnet-delegation-from-an-azure-service

    If the above steps do not help in fixing your issue, we may need to raise a support ticket to get the Service Association Link (SAL) deleted from the backend.

    So, if you have a support plan, I request you file a support ticket, else please do let us know, we will try and help you get a one-time free technical support. In case you need help with a one-time free support, please respond to the private message with the requested details.

    Kindly let us know if the above helped or you need further assistance on this issue.


    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments