Error Encountered with 'az cloud register' when Adding ARM Endpoint and API Version
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). This function relies on msrestazure, which has been deprecated. It eventually calls msrestazure.azure_cloud._populate_from_metadata_endpoint (link).
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).
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).
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 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
Hi @rorozcov,
2.57.0 is not the latest Azure CLI(2.59.0).
If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.
Thank you for opening this issue, we will look into it.
Previously there was an attempt https://github.com/Azure/azure-cli/pull/25834 to bump /metadata/endpoints API version from 2015-01-01 to 2022-09-01. However, that feature got suspended due to other high priority tasks.