Error Encountered with 'az cloud register' when Adding ARM Endpoint and API Version
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
### Describe the bug
I've been trying to use az cloud register, and I'm hitting an error. Whenever I try to add a cloud with its ARM endpoint, I encounter an error. For instance, attempting to register AzureCloud with the AzureCloud ARM endpoint and API version throws an error.
Upon digging deeper, I found that in azure-cli/src/azure-cli/azure/cli/command_modules/cloud/custom.py, there's a function called _build_cloud ([link](https://github.com/Azure/azure-cli/blob/6771b2b1ef04ed2f8e71b636eccce5cf68a7d76d/src/azure-cli/azure/cli/command_modules/cloud/custom.py#L37C5-L37C17)). This function relies on msrestazure, which has been deprecated. It eventually calls msrestazure.azure_cloud._populate_from_metadata_endpoint ([link](https://github.com/Azure/msrestazure-for-python/blob/188184a4e640c6aa0a3eee631a8fbe3c14b108c6/msrestazure/azure_cloud.py#L204)).
Inside _populate_from_metadata_endpoint, there's an API call to the given ARM endpoint, where the error occurs. It seems like the ARM endpoint is expected to not include the API version, so including it causes a hiccup. Additionally, _populate_from_metadata_endpoint uses a hardcoded API version, which is outdated by now ([link](https://github.com/Azure/msrestazure-for-python/blob/188184a4e640c6aa0a3eee631a8fbe3c14b108c6/msrestazure/azure_cloud.py#L35C1-L35C25)).
I'm a bit lost on how to tackle this bug. The msrestazure package has been split into azure-mgmt-core and azure-identity, but I haven't found a direct replacement for its functionality.
I'm keen to chip in and fix this issue, but I'd love your thoughts on the best approach.
Also, just an observation: Az PowerShell supports any version of the ARM endpoint from my experience, unlike what the CLI currently allows ([link](https://learn.microsoft.com/en-us/powershell/module/servicemanagement/azure/add-azureenvironment?view=azuresmps-4.0.0)).
### Related command
az cloud register --name "AzureCloud" --endpoint-resource-manager "https://management.azure.com/metadata/endpoints?api-version=2019-05-01"
### Errors
The stacktrace leads to azure_cloud.py in [msrestazure](https://github.com/Azure/msrestazure-for-python/blob/188184a4e640c6aa0a3eee631a8fbe3c14b108c6/msrestazure/azure_cloud.py#L218) and the error is:
AttributeError: 'list' object has no attribute 'get'
This error goes away when you use the domain name rather than including the API version in "https://management.azure.com/metadata/endpoints?api-version=2019-05-01".
### Issue script & Debug output
N/A
### Expected behavior
I expect it to register the cloud or tell me the cloud was already registered. I use AzureCloud as an example of this failure.
### Environment Summary
azure-cli versions: 2.58.0
core: 2.58.0
telemetry: 1.1.0
msal: 1.26.0
azure-mgmt-resource: 23.1.0b2.
I have also seen this issue in azure-cli: 2.57.0
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.