Search code examples
azureazure-monitor-workbooksazure-resource-graph

Create a Parameter containing list of Subscriptions grouped by Tenant/Directory - Azure Resource Graph


I'm trying to create a Workbook Parameter drop down, where we can choose Subscription to filter.
However, 1 Tenant/ Directory might have one or more subscriptions.
Instead of a flat subscription drop-down list like this:,

  • Subscription-1
  • Subscription-2
  • Subscription-3
  • Subscription-4
  • Subscription-5

Is there a way to create a drop-down list of subscription grouped by Tenant/Directory similar to the ones in Azure Resource Graph Explorer page (located in the right side) like this:?

Tenant 1

  • Subscription-1
  • Subscription-2

Tenant 2

  • Subscription 3

Tenant 3

  • Subscription 4
  • Subscription-5

Thank you very much for your help.


Solution

  • A partial solution:

    1. create a new parameter
    2. pick "subscription picker" as the parameter type
    3. pick "query" as the "get data from" option
    4. in the query, set the data source to "Azure Resource Graph"
    5. pick all or default (subscription filtered subs) as the subscriptions value
    6. use the query
    ResourceContainers | where type =~ "microsoft.resources/subscriptions"
    // add any other filters you want here
    | project id, name, group=tenantId
    

    you'll get a dropdown parameter that is subs grouped by tenant.

    limitation: Azure Resource Graph doesn't have tenant names (not sure why), so the dropdown itself won't have those. you'd possibly have to query ARM separately to get all the tenants by name+id and merge with that if you want tenant names?

    Update: Jason went the extra step of using merge to get data, which i'm not sure why i didn't think of that.

    you could possibly use the ARM data source and query the /tenants api to get that info to use in the merge: enter image description here

    in my place i'm only getting on tenant back in that list, though, so i can't verify that it will work and get you all the tenants. i swear i have access to more than one but i'm only getting back my primary one?