Skip to content
Get Started for Free

Resource Graph

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.

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:

Terminal window
lstk az start-interception

This 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:

Terminal window
lstk az stop-interception

This reconfigures the az CLI to send commands to the official Azure management REST API.

Create a resource group for the resources you want to query:

Terminal window
az group create \
--name rg-resourcegraph-demo \
--location westeurope
Output
{
"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 an App Service plan and a Web App, which we will query using Resource Graph:

Terminal window
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"
Output
{
"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.

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.

Terminal window
az graph query \
--graph-query "Resources | where type =~ 'Microsoft.Web/sites' | project id, name, type, location, resourceGroup, subscriptionId"
Output
{
"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:

Terminal window
az graph query \
--graph-query "Resources | where type =~ 'Microsoft.Web/sites' and name =~ 'ls-app-doc81' | project id"
Output
{
"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:

Terminal window
az graph query \
--graph-query "Resources | where resourceGroup =~ 'rg-resourcegraph-demo' | count"
Output
{
"count": 1,
"data": [
{
"Count": 2
}
],
"skip_token": null,
"total_records": 1
}

List resources sorted by name with a row limit:

Terminal window
az graph query \
--graph-query "Resources | where resourceGroup =~ 'rg-resourcegraph-demo' | project name, type | order by name asc | limit 5"
Output
{
"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:

Terminal window
az graph query \
--graph-query "Resources | where type =~ 'Microsoft.Web/sites' and name =~ 'doesnotexist'"
Output
{
"count": 0,
"data": [],
"skip_token": null,
"total_records": 0
}

An alternative way to invoke Azure Resource Graph is to call its REST API directly using the az rest command:

Terminal window
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\"}}"
Output
{
"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
}

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 Resources and resource groups and subscriptions in ResourceContainers. 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 $skipToken for 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.resultFormat to table for columns and rows, or objectArray for an array of objects. API versions from 2021-03-01 default to objectArray; older versions default to table. 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, and coalesce.
  • Comparison operators: Use ==, !=, =~, !~, contains, !contains, contains_cs, !contains_cs, startswith, !startswith, endswith, !endswith, has, !has, in, !in, and matches regex.
  • Aggregate functions: count(), dcount(), countif(), sum(), sumif(), avg(), min(), and max() for use in summarize stages.
  • Additional tables: Known tables other than Resources and ResourceContainers currently 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-expand operations. 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/limit ignores $skip and does not provide continuation tokens. Results containing only dynamic columns cannot continue either. Use an explicit sort when paging to make the ordering predictable.

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.

8 of 8 operations implemented

Operation ▲Implemented ▼
Page 1 of 0
Was this page helpful?