Delegated subnet deletion error due to SAL


Using terraform modules to create Azure - MySql DB flexible server. Here below I’m mentioning the resources which created along with server:
1.Delegated subnet
2.Mysql database
3. storage

I’m using the existing network resource like,
Private DNS Zone
Vnet link between DNS & Vnet - Not creating along with server

Able to provision every resources without any interruptions via terraform commands (only apply)& Json file. while creating I could come to know that the subnet establishing a SAL (Service Association Link) implicitly.

When try to delete the resources via terraform commands (only apply) & Json file, getting a subnet error saying that,
Error message:││ Subnet Name: “subnet_name”): network.SubnetsClient#Delete: Failure sending request: StatusCode=400 – Original Error: Code=“InUseSubnetCan
notBeDeleted” Message=“Subnet “subnet_name” is in use by /subscriptions/“subscription_id”/resourceGroups/mysql-rg/pro
viders/Microsoft.Network/virtualNetworks/example-vnet/subnets/“subnet_name”/serviceAssociationLinks/“link_id”-sal and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See” Details=

privacy purpose, hided Subnet name, link_id & subscription details

I could able to delete all the Mysql server resource(Server, DB, Storage account, NSG) but not subnet due to SAL.
This issue occurs in postgresql flexible server as well. please provide a solution on this.

If any details required kindly reach out. Thanks!

To resolve the subnet deletion error due to an existing Service Association Link (SAL) with your Azure MySQL Flexible Server, follow these steps:

1.	Ensure all resources in the subnet, including the MySQL Flexible Server, are deleted.
2.	Manually remove the SAL from the subnet using Azure CLI or PowerShell, as Terraform doesn’t directly manage SALs.
•	Use az network vnet subnet update with the --remove serviceAssociationLinks option in Azure CLI.
3.	Retry deleting the subnet with Terraform after removing the SAL.
4.	If the subnet was manually modified or removed, update the Terraform state using terraform refresh or terraform state rm.

Make sure your account has the necessary permissions and there are no locks on the resources. If the problem continues, contact Azure Support for further assistance.