Resource Graph
Introduction
Section titled “Introduction”Azure Resource Graph (ARG) is a service for querying Azure resources at scale using a structured query language. It helps you search, filter, and project resource metadata across subscriptions. Resource Graph is useful for inventory, governance checks, and automated analysis workflows. For more information, see Azure Resource Graph overview.
LocalStack for Azure enables users to explore resources deployed within the local environment using Kusto Query Language (KQL).
The supported APIs are available in the API Coverage section.
Getting started
Section titled “Getting started”This guide is designed for users new to Resource Graph and assumes basic knowledge of the Azure CLI and our lstk az proxy.
Launch LocalStack using your preferred method. For more information, see Introduction to LocalStack for Azure. Once the container is running, enable Azure CLI interception by running:
lstk az start-interceptionThis command points the az CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API.
To revert this configuration, run:
lstk az stop-interceptionThis reconfigures the az CLI to send commands to the official Azure management REST API.
Create a resource group
Section titled “Create a resource group”Create a resource group for the resources you want to query:
az group create \ --name rg-resourcegraph-demo \ --location westeurope{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-resourcegraph-demo", "location": "westeurope", "managedBy": null, "name": "rg-resourcegraph-demo", "properties": { "provisioningState": "Succeeded" }, "tags": null, "type": "Microsoft.Resources/resourceGroups"}Create sample web resources
Section titled “Create sample web resources”Create an App Service plan and a Web App, which we will query using Resource Graph:
az appservice plan create \ --name asp-doc81 \ --resource-group rg-resourcegraph-demo \ --location westeurope \ --is-linux \ --sku F1
az webapp create \ --name ls-app-doc81 \ --resource-group rg-resourcegraph-demo \ --plan asp-doc81 \ --runtime "PYTHON:3.11"{ "asyncScalingEnabled": false, "elasticScaleEnabled": false, "geoRegion": "West Europe", "hyperV": false, "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-resourcegraph-demo/providers/Microsoft.Web/serverfarms/asp-doc81", ... "name": "asp-doc81", ... "status": "Ready", "subscription": "00000000-0000-0000-0000-000000000000", ...}{ ... "enabledHostNames": [ "ls-app-doc81.azurewebsites.azure.localhost.localstack.cloud:4566", "ls-app-doc81.scm.azurewebsites.azure.localhost.localstack.cloud:4566" ], ... "hostNameSslStates": [ { "hostType": "Standard", "name": "ls-app-doc81.azurewebsites.azure.localhost.localstack.cloud:4566", "sslState": "Disabled", "thumbprint": null, "toUpdate": null, "virtualIp": null }, ... ], "hostNames": [ "ls-app-doc81.azurewebsites.azure.localhost.localstack.cloud:4566" ], ...}LocalStack returns host names that point to your emulator host and port. Real Azure returns azurewebsites.net host names.
Query resources with Resource Graph
Section titled “Query resources with Resource Graph”The Resource Graph extension must be installed to use az graph commands. Refer to the official installation instructions. Use the az graph query command to run Kusto Query language (KQL) queries against the emulator.
The following examples demonstrate common query patterns:
The example outputs assume only the walkthrough’s resources are in scope. Real Azure indexes resource changes asynchronously; if a newly created resource is missing, run the query again after a short wait.
az graph query \ --graph-query "Resources | where type =~ 'Microsoft.Web/sites' | project id, name, type, location, resourceGroup, subscriptionId"{ "count": 1, "data": [ { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-resourcegraph-demo/providers/Microsoft.Web/sites/ls-app-doc81", "location": "westeurope", "name": "ls-app-doc81", "resourceGroup": "rg-resourcegraph-demo", "subscriptionId": "00000000-0000-0000-0000-000000000000", "type": "microsoft.web/sites" } ], "skip_token": null, "total_records": 1}Query a web site by type and name, projecting only the id column. The Azure CLI adds resourceGroup to the displayed output:
az graph query \ --graph-query "Resources | where type =~ 'Microsoft.Web/sites' and name =~ 'ls-app-doc81' | project id"{ "count": 1, "data": [ { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-resourcegraph-demo/providers/Microsoft.Web/sites/ls-app-doc81", "resourceGroup": "rg-resourcegraph-demo" } ], "skip_token": null, "total_records": 1}Count all resources in a resource group:
az graph query \ --graph-query "Resources | where resourceGroup =~ 'rg-resourcegraph-demo' | count"{ "count": 1, "data": [ { "Count": 2 } ], "skip_token": null, "total_records": 1}List resources sorted by name with a row limit:
az graph query \ --graph-query "Resources | where resourceGroup =~ 'rg-resourcegraph-demo' | project name, type | order by name asc | limit 5"{ "count": 2, "data": [ { "name": "asp-doc81", "type": "microsoft.web/serverfarms" }, { "name": "ls-app-doc81", "type": "microsoft.web/sites" } ], "skip_token": null, "total_records": 2}Query a resource that does not exist:
az graph query \ --graph-query "Resources | where type =~ 'Microsoft.Web/sites' and name =~ 'doesnotexist'"{ "count": 0, "data": [], "skip_token": null, "total_records": 0}Query resources with the REST API
Section titled “Query resources with the REST API”An alternative way to invoke Azure Resource Graph is to call its REST API directly using the az rest command:
az rest --method post \ --url "http://azure.localhost.localstack.cloud:4566/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01" \ --headers "Content-Type=application/json" \ --body "{\"subscriptions\":[\"00000000-0000-0000-0000-000000000000\"],\"query\":\"Resources | where type=~'Microsoft.Web/sites' | project id, name, type, location, resourceGroup, subscriptionId\", \"options\":{\"resultFormat\":\"objectArray\"}}"{ "count": 1, "data": [ { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-resourcegraph-demo/providers/Microsoft.Web/sites/ls-app-doc81", "location": "westeurope", "name": "ls-app-doc81", "resourceGroup": "rg-resourcegraph-demo", "subscriptionId": "00000000-0000-0000-0000-000000000000", "type": "microsoft.web/sites" } ], "facets": [], "resultTruncated": "false", "totalRecords": 1}Features
Section titled “Features”The Resource Graph emulator supports the following features:
- Shared KQL query engine: Queries use the same engine as Log Analytics, built on Microsoft’s KQL grammar. See the KQL guide for the shared language support; ARG applies the limits below.
- Resource inventory: Query resources in
Resourcesand resource groups and subscriptions inResourceContainers. Resource rows expose tags and typed, modeled ARM fields, including nested properties, SKU, kind, and identity where the resource model provides them. - Scope and authorization: Explicit subscription scopes restrict both tables. Omitting a scope queries the emulated tenant. When Azure Role-Based Access Control (RBAC) enforcement is enabled with
LS_AZURE_ENFORCE_RBAC, the emulator filters input rows by the caller’s read permissions before executing KQL, including joins and aggregations. - Paging and facets: Use
$top,$skip, and$skipTokenfor result pages, and request facets over the full query result. - Saved queries: Create, read, update, delete, and list graph queries. ETags support conditional updates.
- Tabular and object result formats: Set
options.resultFormattotablefor columns and rows, orobjectArrayfor an array of objects. API versions from2021-03-01default toobjectArray; older versions default totable. An explicit format overrides the default. - Scalar functions: Built-in functions including
tolower,toupper,strlen,trim,substring,strcat,isnull,isnotnull,isempty,isnotempty,tostring,toint,tolong,todouble, andcoalesce. - Comparison operators: Use
==,!=,=~,!~,contains,!contains,contains_cs,!contains_cs,startswith,!startswith,endswith,!endswith,has,!has,in,!in, andmatches regex. - Aggregate functions:
count(),dcount(),countif(),sum(),sumif(),avg(),min(), andmax()for use insummarizestages.
Limitations
Section titled “Limitations”- Additional tables: Known tables other than
ResourcesandResourceContainerscurrently return empty results. Unknown table names return a query error. - Management groups: Management-group query scopes and hierarchy data are not emulated. Unsupported scopes return an error.
- Shared-query references: Preview
{{shared-query-uri}}substitution is not supported. - ARG limits: Queries allow three combined join/union operations and three
mv-expandoperations. Expansion defaults to 128 rows per input, with a maximum of 2,000. These are ARG-specific limits; Log Analytics does not apply a per-input-row expansion limit by default. - Result size: Pages return up to 1,000 rows.
take/limitignores$skipand does not provide continuation tokens. Results containing only dynamic columns cannot continue either. Use an explicit sort when paging to make the ordering predictable.
Supported tabular operators
Section titled “Supported tabular operators”The table below lists the KQL tabular operators supported by Azure Resource Graph and their availability in the LocalStack emulator. For the full reference, see Supported tabular/top-level operators.
| Operator | Supported | Notes |
|---|---|---|
count |
Yes | Returns a single row with the total number of input rows. |
distinct |
Yes | Deduplicates rows by the specified columns. |
extend |
Yes | Adds computed columns to the result set. |
join |
Yes | Supports innerunique, inner, leftouter, and fullouter. |
limit |
Yes | Synonym of take. |
mv-expand |
Yes | Expands arrays and property bags, including kind=array and kind=bag. |
order |
Yes | Synonym of sort. Supports asc and desc directions. |
parse |
Yes | Extracts columns using string patterns. |
project |
Yes | Supports column selection and aliased expressions. |
project-away |
Yes | Removes specified columns from the result set. |
sort |
Yes | Synonym of order. |
summarize |
Yes | Supports aggregate functions with an optional by clause. |
take |
Yes | Synonym of limit. |
top |
Yes | Returns the first N rows sorted by specified columns. |
union |
Yes | Combines results within ARG’s join/union budget. |
where |
Yes | Filters rows using comparison, logical, and string operators. |
Table legend: Operator names the KQL operator, Supported indicates emulator availability, and Notes describes its behavior or restrictions.
API Coverage
Section titled “API Coverage”8 of 8 operations implemented
| Operation ▲ | Implemented ▼ |
|---|