Share via

Can't delete VNET due to subnet

Nutpapon Limsupavanich 20 Reputation points
2026-04-17T03:15:46.67+00:00

Hi.

I did some provision testing for AI resources bicep and want to delete resources. I tried to delete the VNet and got this error.

Failed to delete virtual network 'agent-vnet-test'. Error: Subnet agent-subnet is in use by /subscriptions/xxxxx-xxxxx/resourceGroups/ai-private-infra-02/providers/Microsoft.Network/virtualNetworks/agent-vnet-test/subnets/agent-subnet/serviceAssociationLinks/legionservicelink and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.

Then, I tried to delete the subnet and remove delegation but also has this error.

Failed to delete subnet 'agent-subnet'. Error: Subnet agent-subnet is in use by /subscriptions/xxxxx-xxxxx/resourceGroups/ai-private-infra-02/providers/Microsoft.Network/virtualNetworks/agent-vnet-test/subnets/agent-subnet/serviceAssociationLinks/legionservicelink and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.

Failed to save subnet 'agent-subnet'. Error: 'Subnet /subscriptions/xxxxx-xxxxx/resourceGroups/ai-private-infra-02/providers/Microsoft.Network/virtualNetworks/agent-vnet-test/subnets/agent-subnet requires any of the following delegation(s) [Microsoft.App/environments] to reference service association link /subscriptions/xxxxx-xxxxx/resourceGroups/ai-private-infra-02/providers/Microsoft.Network/virtualNetworks/agent-vnet-test/subnets/agent-subnet/serviceAssociationLinks/legionservicelink. Those delegations are either missing or getting deleted from subnet.'

Please suggest me how to delete these resources.

Bests,

Kong

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.


Answer accepted by question author

  1. Aditya N 2,875 Reputation points Microsoft External Staff Moderator
    2026-04-17T04:03:22.1733333+00:00

    Hello @Nutpapon Limsupavanich

    Thank you for reaching out Microsoft Q&A. Please could you let us know if you have checked the dependencies for the Vnet.

    serviceAssociationLinks/legionservicelink

    Regarding this, please use below purge command, it will take around 24 hours then you can go ahead and delete subnet.

    az rest --method POST \      --uri "/subscriptions/<SUBSCRIPTION-ID>/providers/Microsoft.Web/locations/<LOCATION>/purgeUnusedVirtualNetworkIntegration?api-version=2024-04-01" \      --body "{'subnetResourceId': '<SUBNET-RESOURCE-ID>'}"

    Replace the parameters with yours.

    1 person found this answer helpful.
    0 comments No comments

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.