azure-sdk-for-go
azure-sdk-for-go copied to clipboard
armresourcegraph: Inconsistent casing causes resources not to be found from graph API
Inconsistent casing, combined with ids being case-sensitive, causes resources not to be found from graph API.
Note: This seems to originate from the graph api itself, since https://portal.azure.com/#view/HubsExtension/ArgQueryBlade shows the same results.
I have a list of resource ids that originate from armauthorization.RoleAssignmentsClient
, which I take from the responses Properties.Scope
. I then use armresourcegraph to load the various types of resources to obtain tags.
This works in most cases, however, not for redis. The casing of the ID returned by armauthorization differs from what is expected by the graph API.
# ID as returned by armauthorization SDK.
# Does not return result in graph
Resources | where id == '/subscriptions/<my-sub>/resourceGroups/<my-rg>/providers/Microsoft.Cache/redis/<my-redis>' | project id, name, type, resourceGroup, tags
# Fixing casing to the exact type returned when fetching from cli (az resource show --ids "<the-id>")
* Note: redis -> Redis
Resources | where id == '/subscriptions/<my-sub>/resourceGroups/<my-rg>/providers/Microsoft.Cache/Redis/<my-redis>' | project id, name, type, resourceGroup, tags
I run use these queries via:
// *armresourcegraph.Client
ResourceGraphClient.Resources(context.Background(), armresourcegraph.QueryRequest{
Query: to.Ptr(q),
}, nil)
Some inconsistencies can be observed throughout the Azure landscape that make the graph API hard to navigate.
-
Inconsistent strictness of id casing: When using cli
az resource show --ids "<id-with-lowercase-redis">
this gives the result. The graph API does not. Theaz resource
cli command uses dedicated per-resource APIs under the hood. Nevertheless confusing -
Inconsistent casing of types in ids: In id
Microsoft.Cache/redis
is incorrect, howeverMicrosoft.KeyVault/vaults
is correct -
Inconsistent response casing: The graph response
type
values are casted to lowercase, unlike the JSON response ofaz resource show
. Querying the graph API by type requires this lower case. So querying by id and by type both use strict casing, but require a differently cased value.
I can imagine strict casing is important for all naming entered by users (rg names, resource names, tags, etc.). However the type attribute has a limited and well-defined set of values. Not checking for exact casing would make the armresources SDK and the graph API a lot easier to navigate.
To illustrate, I now have this code fragment to work around this issue:
fixedResourceID := strings.Replace(resourceID, "Microsoft.Cache/redis", "Microsoft.Cache/Redis", -1)