Hi @Wrex ,
Thanks for reaching out to Microsoft Q&A.
As your description, your custom domain is stuck in the deleting state for several weeks. Even after multiple retries using the Azure portal and PowerShell commands, it remains undeleted.
Remove DNS Records Before Deleting Before attempting another delete operation, ensure that all DNS records (CNAME, TXT) associated with the domain are removed from your domain registrar.
Use Azure CLI to Force Delete Try deleting the custom domain using Azure CLI, as it may bypass UI-related issues,
az staticwebapp hostname delete -n "<static-webapp-name>" -g "<resource-group>" --hostname "<custom-domain>"
Use PowerShell Script (Retry Delete Until Success) If the CLI fails, use a PowerShell loop to keep retrying the deletion until it succeeds.
$name = "<static-webapp>";
$remove_me = "sub.domain.com";
$domains = Get-AzStaticWebAppCustomDomain -ResourceGroupName $rg -Name $name;
$len = $domains.Length;
while($len -eq $domains.Length){
foreach($item in $domains){
if($item.name -eq $remove_me){
$err = Remove-AzStaticWebAppCustomDomain -DomainName $remove_me -Name $name -ResourceGroupName $rg -NoWait;
$domains = Get-AzStaticWebAppCustomDomain -ResourceGroupName $rg -Name $name;
if($domains.Length -gt 0){
Write-Host "$remove_me still exists. Retrying...";
Start-Sleep -s 10;
}
}
}
}
Write-Host "Success!";
Give Deleting a Shot via Azure Resource Explorer
Open it up
Head to: subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/staticSites/{static-web-app-name}/customDomains/{domain-name}
Try deleting the domain manually.
Look for Azure Resource Locks If your Static Web App or resource group has a delete lock, remove it by going to: Azure Portal > Resource Group > Settings > Locks
ref:
https://learn.microsoft.com/en-us/answers/questions/923400/unable-to-delete-custom-domain-from-static-web-app
Let me know if you have any further assistances.
If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.