Share via

Failed to create web app using azure cli

Som Shrivastava 40 Reputation points
2026-05-27T12:06:30.41+00:00

I am using an Azure CLI script to create a web app, but I’m encountering the following error:

Webapp 'XXX-XXX-XXX' already exists. The command will use the existing app's settings. Unable to retrieve details of the existing app 'XXX-XXX-XXX'. Please check that the app is part of the current subscription. If creating a new app, app names must be globally unique. Please try a more unique name.

However, when I manually create a web app with the same name through the Azure Portal, it succeeds without any issues.

Additional context:

The same script used to work previously.

I have created and deleted web apps with this same name multiple times in the past.

After about 6 months, the script has suddenly stopped working.

I can confirm there is no active web app with this name in any subscription.

Azure App Service
Azure App Service

Azure App Service is a service used to create and deploy scalable, mission-critical web apps.


Answer accepted by question author

Andrew Taylor - COREZENN 980 Reputation points Volunteer Moderator
2026-05-27T17:52:56.2266667+00:00

Hello @Som Shrivastava

Thank you for reaching out to the Microsoft Q&A platform. My name is Andrew and I am happy to help with your concerne.

I understand you are having an issue with Azure Web App and the corresponding CLI.


Problem summary The CLI error means the App Service name is already present somewhere the service can see, but the CLI cannot retrieve its details in the current subscription/tenant/context. Common causes: the name is taken by a Web App or Function App in another subscription/tenant, a stale/cached view in the CLI, or a permissions/tenant mismatch.

Verified quick checklist and fixes

  1. Ensure you're using the correct tenant/subscription
  • Confirm current account and subscription: az account show -o table
  • If wrong, switch to the intended subscription: az account set --subscription <subscription-id-or-name>
  1. Search all subscriptions for any Microsoft.Web/sites resource with that name

Bash (Linux/macOS / WSL / Git Bash):

NAME=your-webapp-name
for sub in $(az account list --query "[].id" -o tsv); do
	az resource show --resource-type Microsoft.Web/sites --name $NAME --subscription $sub -o json && echo "FOUND in $sub" && break || true
done

PowerShell (Windows):

$name = 'your-webapp-name'
az account list --query "[].id" -o tsv | ForEach-Object {
	$sub = $_
	try {
		az resource show --resource-type Microsoft.Web/sites --name $name --subscription $sub -o json | Out-Null
		Write-Host "FOUND in subscription: $sub"
		break
	} catch { }
}

Note: Function Apps, Web Apps and deployment slots share the same Microsoft.Web/sites namespace; the command covers those.

  1. If you find the resource in another subscription/tenant
  • Either delete it (if intended) or use the correct subscription/credential when running the CLI.
  1. If you don't find any resource
  • Clear/local-cached auth and re-authenticate, then re-run with debug to inspect REST errors: az logout az login az webapp create ... --debug
  • Also update Azure CLI (fixes some bugs): az upgrade
  1. If Portal can create the app but CLI still fails
  • Compare the REST calls shown by Portal (Activity log) vs CLI --debug output. The mismatch usually reveals a tenant/subscription boundary or permission issue.

When to escalate

  • If the commands above don't find the name and re-login/upgrade don't help, open an Azure Support ticket including the --debug CLI output and the subscription/tenant IDs you checked; Microsoft support can inspect backend reservations or soft-deleted hostnames.

Notes

  • The hostname space is global for App Service within the public Azure cloud; a name taken in any subscription/tenant in the same cloud prevents creation.
  • Searching Microsoft.Web/sites across all subscriptions is the most reliable way to prove whether the name is actually in use.
I hope this helps with your issue and if you find this information to be helpful, please mark this answer as "accepted" and this helps the community find helpful answers. Also please follow me here on Microsoft Learn Q&A.

Best regards,
Andrew Taylor

Was this answer helpful?

2 people found this answer helpful.

Answer accepted by question author

Golla Venkata Pavani 6,000 Reputation points Microsoft External Staff Moderator
2026-05-28T14:10:44.9233333+00:00

Hi @Som Shrivastava ,

Thanks for the update and Andrew for providing response.

Since you deleted the App Service approximately six months ago, the 30-day soft-delete retention period has long passed, and the name should now be available for reuse. However, Azure holds onto names for a bit longer sometimes due to internal DNS propagation and subdomain takeover protection mechanisms. This can occasionally cause the “already exists” error to persist even after the retention window.

Next recommendation:

  1. Verify current name availability using this command:
az rest --method post --url "/providers/Microsoft.Web/checkNameAvailability?api-version=2022-03-01" \
  --body '{"name": "XXX-XXX-XXX", "type": "Microsoft.Web/sites"}'
  1. If the check returns {"nameAvailable": true}, try creating the web app again with the CLI.

Reference:
https://learn.microsoft.com/en-us/troubleshoot/azure/app-service/create-delete-resources-faq-new
https://learn.microsoft.com/en-us/azure/app-service/app-service-undelete?tabs=portal
https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules

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

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

Was this answer helpful?

1 person found this answer helpful.

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.