Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
402 stars 195 forks source link

Add subscription/region selection to `azd env refresh`? #2415

Open savannahostrowski opened 1 year ago

savannahostrowski commented 1 year ago

Let me outline a UX flow from Azure App Spaces. However, this is relevant beyond just the Azure App Spaces scenario.

  1. Deploy an azd template from Azure App Spaces
  2. Open the new repo created in Codespaces (or git clone)
  3. Run azd auth login
  4. Run azd env refresh <env name> to pull the env metadata down

Notice that you get this error: image

We have an empty config at this point and the user has not yet been walked through the subscription/region flow so azd thinks the environment doesn't exist.

savannahostrowski commented 1 year ago

cc: @ellismg for input here too!

ellismg commented 1 year ago

We have an empty config at this point and the user has not yet been walked through the subscription/region flow so azd thinks the environment doesn't exist.

This is a good issue. We certainly have gaps here.

For refresh to work today, we have to find the most recent deployment that corresponds to the user's infrastructure.

For subscription based deployments, we need to know the subscription ID so we can list all the deployments and find the one tagged with azd-env-name that corresponds to the environment they are trying to refresh.

For resource group based deployments, we need to know both the subscription and the target resource group.

So, before we can preform the refresh operation, we will need to prompt the user for what subscription they want to use. We can recover the AZURE_LOCATION setting by using the location of the most recent deployment, so we shouldn't need to prompt for that value.

It seems like when running the command azd env refresh <env-name> if env-name doesn't exist, we shouldn't prompt if the user wants to create this (their intention is pretty clear from the command) but we will still need to ask about which subscription (and possibly resource group) to use and then do the refresh.

rajeshkamal5050 commented 1 year ago

@ellismg @savannahostrowski adding it to the Germanium bucket. We can pull it into iterations/sprints as part of planning.

john0isaac commented 11 months ago

I'd like to work on fixing this.

wbreza commented 11 months ago

@savannahostrowski / @ellismg - i wonder if App Spaces would be a good candidate for a remote environment provider

john0isaac commented 10 months ago

The root cause of this issue is the execution of the function in the pkg/environment Manager.LoadOrCreateInteractive() as it's a part of the initialization process of a new environment so, any package that depends on the environment package will trigger this function first.

These are some things I tried and they did not work: 1- remove the packages that have *environment.Environment found three projectManager, provisioningManager, env. ==> (Bad path - can't remove them as they are essential for the current functionality) 2- fixing the function that does this Environment.Manager.LoadOrCreateInteractive() ==> (some progress - using provisioing.Manager.EnsureSubscriptionAndLocation() creates circular dependency between packages) 3- refactoring the code to be able to use the EnsureSubscriptionAndLocation() function or replicate its functionality without using it in Environment.Manager.LoadOrCreateInteractive().

I tried but everything I try changes the functionality of the existing code so, I suggest we create a new Prompter package that doesn't depend on the Environment with the needed functionality. plus, for Resource groups don't show an option to create a new resource group.