Unable to use az from OOBE when setting ARM_CLOUD_METADATA_URL
This is autogenerated. Please review and update as needed.
Describe the bug
In the AGCs we rely on setting the ARM_CLOUD_METADATA_URL environment variable to load the cloud endpoints from ARM. When a new user tries to run any az commands when this environment variable is set, the error below is shown because ~\.azure has not been created yet.
If I manually create ~\.azure, the commands succeed as normal.
Command Name
az cloud set --name AGC
Errors:
PS C:\Users\rofrazie> az cloud set --name AGC --verbose --debug
Traceback (most recent call last):
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_session.py", line 37, in load
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\rofrazie\\.azure\\cloudEndpoints.json'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "runpy.py", line 196, in _run_module_as_main
File "runpy.py", line 86, in _run_code
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/__main__.py", line 16, in <module>
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/intercept_survey.py", line 11, in <module>
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_profile.py", line 13, in <module>
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/cloud.py", line 459, in <module>
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/cloud.py", line 429, in get_known_clouds
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_session.py", line 50, in load
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_session.py", line 54, in save
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\rofrazie\\.azure\\cloudEndpoints.json'
To Reproduce:
Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.
- Download the endpoint metadata to an endpoints.json file locally from ARM here: https://management.azure.com/metadata/endpoints?api-version=2020-09-01
- Modify the file to change the name of the "AzureCloud" cloud to "AGC", remove the other clouds
- From the same directory as endpoints.json, start up a python server to serve the file
python3 -m http.server - Set the environment variable
$env:ARM_CLOUD_METADATA_URL = "http://localhost:8000/endpoints.json" - Delete your
~\.azuredirectory - Run any az command
Expected Behavior
The ~\.azure directory should be created if it doesn't exist and the command should run
Environment Summary
Windows-10-10.0.22621-SP0
Python 3.10.8
Installer: MSI
azure-cli 2.43.0
Additional Context
@evelyn-ys for awareness
Hi @toefraz!
I have reproduced the behavior and obtained the same error as yours. The error happened when imported the package prompt_survey_message in __main__.py#L16 which called the function get_known_clouds in cloud.py#L459. This function will check whether the environment variable ARM_CLOUD_METADATA_URL exists. It had happened before we checked the state of ~/.azure folder when initializing the AzCli instance in __main__.py#L39. This is why we got this error.
In this scenario, removing the ~/.azure folder is not a good solution. Instead, running az cloud register --name AGC is a better option.
Regarding this error, it doesn't seem like a proper behavior. I will investigate and provide a fix.
Thanks for looking into this, @MoChilia!