-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[QUERY] How to retrieve Availability Zone information directly from GenericResource? #48574
Description
Query/Question
We are using azure.genericResources().listByResourceGroup(<resource-group-name>) to generate a complete inventory of all resources within a Resource Group regardless of their type.
Our requirement is to capture the Availability Zone ("zonal") information for resources that support it (VMs, Disks, etc.). In the raw REST API and Azure CLI, the "zones" array is returned as a top-level property next to "type" and "properties":
"type": "Microsoft.Compute/virtualMachines",
"zones": [ "2" ],
"properties": { ... }However, when inspecting the GenericResource object returned by the Java SDK, the top-level zones array does not appear to be exposed. It is not mapped into the resource.properties() map, nor is it accessible directly on the GenericResource interface.
Our Current Workaround:
When we iterate through the generic resources, we check the type and dynamically fetch the strongly-typed object to access the zones:
if (resource.type().equalsIgnoreCase("Microsoft.Compute/virtualMachines")) {
VirtualMachine vm = azure.virtualMachines().getById(resource.id());
Set<String> zones = vm.zones();
}The Problem: This introduces a severe N+1 API call issue. If a resource group has 100 VMs and Disks, we are forced to make 101 API calls just to retrieve the zone metadata, which heavily impacts performance.
The Ask: Is there a supported way to extract the raw "zones" array directly from the GenericResource (or its innerModel()) returned by listByResourceGroup() to avoid making individual .getById() calls for every resource?
Why is this not a Bug or a feature Request?
This is not a bug because GenericResource is behaving as designed by wrapping standard ARM properties and dropping unmapped top-level keys. It is also not a feature request (yet), as we are inquiring if there is an existing best practice, hidden property bag, or specific SDK deserialization setting we might have missed that allows access to raw top-level ARM JSON properties within the GenericResource wrapper.
Setup (please complete the following information if applicable):
- OS: macOS
- IDE: IntelliJ IDEA / VS Code
- Library/Libraries:
com.azure.resourcemanager:azure-resourcemanager:2.36.0
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Query Added
- Setup information Added