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
369 stars 166 forks source link

[Issue] azd caching old unexistent environment and not using default #3827

Closed luisquintanilla closed 1 week ago

luisquintanilla commented 2 weeks ago

Output from azd version Run azd version and copy and paste the output here:

azd version 1.8.2 (commit 14600c7a54edac4f54397413f8638431f5c16327)

Describe the bug When trying to deploy an application (.NET Aspire) using azd, there is an old environment that appears to be cached.

image

However, that environment is not in my .azure directory.

image

When I create a new environment, it sets it as the default. image

If I try to set environment variables or run azd up, it chooses the old cached environment instead of my default.

image

To Reproduce Not sure how to reproduce since the old environment that's been cached is not on my machine.

Expected behavior azd uses default environment.

Environment Information on your environment:

Additional context

weikanglim commented 2 weeks ago

If I try to set environment variables or run azd up, it chooses the old cached environment instead of my default.

Is it possible that AZURE_ENV_NAME environment variable has been set in the shell?

Print current value:

echo $env:AZURE_ENV_NAME

Unset current value:

$env:AZURE_ENV_NAME = ''

You can also use azd env select <name> to set the explicit default environment.

luisquintanilla commented 1 week ago

If I try to set environment variables or run azd up, it chooses the old cached environment instead of my default.

Is it possible that AZURE_ENV_NAME environment variable has been set in the shell?

Print current value:

echo $env:AZURE_ENV_NAME

Unset current value:

$env:AZURE_ENV_NAME = ''

You can also use azd env select <name> to set the explicit default environment.

Looks like that may be it.

echo $env:AZURE_ENV_NAME
openaidemo100523

I'll give it a try and report back if this fixed the issue.

luisquintanilla commented 1 week ago

Removing the environment variable worked. Marking this issue as fixed and closing. Thanks @weikanglim

luisquintanilla commented 1 week ago

Reopening this issue.

While some of the resources used the correct environment, it seems like others are picking the wrong unexistient environment.

image

image

image

@weikanglim are there other places where this might be cached?

weikanglim commented 1 week ago

@luisquintanilla There shouldn't be any other items that would cause a forced environment selection. What commands aren't working for you? Would you mind providing the command being ran and the command output?

luisquintanilla commented 1 week ago

@luisquintanilla There shouldn't be any other items that would cause a forced environment selection. What commands aren't working for you? Would you mind providing the command being ran and the command output?

I just ran azd up since it's the first time I'm provisioning these services.

image

weikanglim commented 1 week ago

@luisquintanilla Is it possible that you have AZURE_RESOURCE_GROUP set explicitly either in the shell, or in the environment's .env file that has the old value?

# AZURE_RESOURCE_GROUP value in shell
echo $env:AZURE_RESOURCE_GROUP

# Also print values out from the .env file
azd env get-values

You may want to verify all AZURE_ environment variables set in the shell as well:

gci env: | ? { $_.Name.StartsWith("AZURE_") }

And if the environment variables are set at the User or Machine level (they re-appear after opening a new terminal), you may need to remove them at the right scope. See this stack overflow post.

luisquintanilla commented 1 week ago

That did the trick. Thanks again @weikanglim. Closing.