azure-dev icon indicating copy to clipboard operation
azure-dev copied to clipboard

Changing Azure location and re-deploying results in deployment name conflict

Open karolz-ms opened this issue 3 years ago • 4 comments

Repro steps

  1. Initialize the repository via azd init
  2. azd provision
  3. Open the .env file and change AZURE_LOCATION (e.g. from westus to eastus or similar).
  4. Do azd provision again.

Expected

Provisioning should succeed

Actual

Provisioning fails with deployment name conflict (a screenshot from Tim, who brought this scenario to my attention):

MicrosoftTeams-image

karolz-ms avatar Jun 15 '22 17:06 karolz-ms

There are two issues here:

  1. When creating a subscription level deployment - you need to provide a region where the deployment metadata (not the resources themselves) lives. Right now, this is AZURE_LOCATION.

  2. Even if the above didn't fail - I suspect we'd still run into issues with the underlying infrastructure having duplicate names across regions, since the location does not impact the name of the resource we are going to deploy and ARM will not delete the existing resources in the old locations before deploying the new one.

We could mitigate (1), I think, by not reusing the deployment name for each deployment as we do today. I have been thinking this might be a good idea for other reasons.

For Public Preview, it's possible we will be able to address (1). I think that (2) is sort of out of scope, but perhaps we could consider mixing the location value into our hash function for resource suffixes in the templates we produce.

I feel like for public preview we should just tell folks that if they want to change the location, they should use azd down to delete all the existing infrastructure before re-deploying. That should work today end to end.

ellismg avatar Jun 16 '22 18:06 ellismg

I re-produced this. The error included in the original issue is misleading. Tim selected a region that was too busy to create the Cosmo DB account.

I deployed to westus and updated to a region that is ok. e.g., centralus. The error message:

Created App Service plan: plan-rsiqo7swfrhqi Created Log Analytics workspace: log-rsiqo7swfrhqi Created App Service: app-api-rsiqo7swfrhqi Created App Service: app-web-rsiqo7swfrhqi Created Application Insights: appi-rsiqo7swfrhqi Created Portal dashboard: appid-rsiqo7swfrhqi Created Key vault: keyvaultrsiqo7swfrhqi Created Azure Cosmos DB: cosmos-rsiqo7swfrhqi Error: deployment failed: failed deploying: failed running az deployment sub create:

Deployment Error Details: InvalidDeploymentLocation: Invalid deployment location 'centralus'. The deployment 'node810' already exists in location 'westus'.

Potential suggestion: Run azd down to delete all the existing infrastructure before re-deploying.


Additional notes:

  • app service plan, app service etc. are listed as created but in Azure portal, location is still westus.
  • I would expect to see the error message right away instead of waiting for a while before I was told

puicchan avatar Aug 10 '22 20:08 puicchan

After talking through this, we should make sure we use unique deployment names to prevent this from happening.

puicchan avatar Aug 15 '22 20:08 puicchan

I believe this is related to us using the environment name as the deployment name. We may need to randomize the deployment name or include the location in the name.

jongio avatar Aug 17 '22 20:08 jongio

Hello, I'm facing the same issue. It would be great if we had a way to specify the deployment name. Currently if I have several projects using azd in the same subscription, if I use the same location my deployments at the sub level are being overwritten. If I change the location, I get the error mentionned here.

xaviermignot avatar Apr 29 '23 20:04 xaviermignot

@ellismg - Aren't deployment names unique based on env name?

jongio avatar May 01 '23 16:05 jongio