[Feature]: Get-AzSubscription with SubscriptionId parameter should internally only get a single subscription instead of listing all subs then searching #19115
Labels
Accounts
Issues in Az.Accounts except authentication related
feature-request
This issue requires a new behavior in the product in order be resolved.
Tracking
We will track status and follow internally
Milestone
Description of the new feature
When calling Get-AzSubscription using the SubscriptionId parameter:
Get-AzSubscription -SubscriptionId "123582cb-b98a-4200-a7a5-edee9045a123"
Internally, this executes (GetAzureRMSubscription.cs):
this._client.TryGetSubscriptionById(TenantId, this.SubscriptionId, out result)
TryGetSubscriptionById then executes (RMProfileClient.cs)
var subscriptionList = ListSubscriptions(tenantId).Where(s => s.GetId() == subscriptionIdGuid);
This has the effect of listing all subscriptions that the caller has access to, then finding the matching SubscriptionId. Given that a SubscriptionId is unique, there is no need to list them all then find the first matching one.
For a scenario where the caller has access to thousands of subscriptions, this consumes a lot of unnecessary time and resources since the code internally has to iterate over several nextLink results and call the /subscriptions API multiple times.
Proposed implementation details (optional)
TryGetSubscriptionById should instead utilize TryGetTenantSubscription, which does a single GET on a specific subscription.
This will significantly reduce the resource load on both the client and on ARM since there will be much less data returned and fewer API calls being made.
The text was updated successfully, but these errors were encountered: