Skip to content

Azure Resource Graph

Inventory your whole Azure estate with Resource Graph KQL

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/azure-resourcegraph/index.md to help me query Azure Resource Graph with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Count Azure resources across your estate

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT result ->> 'type' AS type, count(*)
FROM azure.main.resourcegraph_query('Resources | project type')
GROUP BY 1
ORDER BY 2 DESC

Quick start

Choose where to run Azure Resource Graph, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-azure-resourcegraph'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

azure_graph credentials

Microsoft Entra app-only (client-credentials) credentials for Azure ARM / Microsoft Graph

Get these credentials β†’
secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Credential fields and requirements β†’

4. Run a query

query.sql
SELECT result ->> 'type' AS type, count(*)
FROM azure.main.resourcegraph_query('Resources | project type')
GROUP BY 1
ORDER BY 2 DESC
More example queries β†’
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Azure Resource Graph β€” whole-estate KQL inventory as a DuckDB table (point-in-time snapshot) β€” vgi-azure-resourcegraph

Catalog

Everything azure exposes once attached β€” read straight from the worker's released build.

azure 1 schema
main 1 view Β· 1 function

Azure Resource Graph β€” one KQL query over the ARM estate as one JSON result row per resource.

Schema examples (5)
Examples (5)

Count resources by type across the estate

SELECT result ->> 'type' AS type, count(*)
FROM azure.main.resourcegraph_query('Resources | project type')
GROUP BY 1
ORDER BY 2 DESC;

Count resources per subscription by display name: join a Resources count per subscriptionId to the subscription rows of ResourceContainers

WITH subs AS (SELECT result ->> 'subscriptionId' AS subscription_id, result ->> 'name' AS subscription_name FROM azure.main.resourcegraph_query('ResourceContainers | where type =~ ''microsoft.resources/subscriptions'' | project subscriptionId, name')) SELECT s.subscription_name, CAST(r.result ->> 'n' AS BIGINT) AS resources
FROM azure.main.resourcegraph_query('Resources | summarize n = count() by subscriptionId') r
JOIN subs s ON s.subscription_id = r.result ->> 'subscriptionId'
ORDER BY resources DESC, s.subscription_name;

Find resources deployed in a different region than their resource group (global and location-less resources excluded): join Resources to the resource-group rows of ResourceContainers

WITH rgs AS (SELECT result ->> 'subscriptionId' AS subscription_id, lower(result ->> 'name') AS resource_group, result ->> 'location' AS group_location FROM azure.main.resourcegraph_query('ResourceContainers | where type =~ ''microsoft.resources/subscriptions/resourcegroups'' | project subscriptionId, name, location')) SELECT g.resource_group, r.result ->> 'name' AS name, r.result ->> 'type' AS type, r.result ->> 'location' AS location, g.group_location
FROM azure.main.resourcegraph_query('Resources | where isnotempty(location) and location != ''global'' | project name, type, resourceGroup, location, subscriptionId') r
JOIN rgs g ON g.subscription_id = r.result ->> 'subscriptionId' AND g.resource_group = lower(r.result ->> 'resourceGroup')
WHERE r.result ->> 'location' <> g.group_location
ORDER BY g.resource_group, name;

List storage accounts with their resource group

SELECT result ->> 'name' AS name,
  result ->> 'resourceGroup' AS resource_group
FROM azure.main.resourcegraph_query('Resources | where type =~ ''microsoft.storage/storageaccounts'' | project name, resourceGroup');
1 more example

Query a single subscription by GUID

SELECT result
FROM azure.main.resourcegraph_query('Resources | project name, location', subscriptions := '00000000-0000-0000-0000-000000000000');
Views
kql_recipes 1 example3 cols

Credential-free menu of curated Azure Resource Graph KQL queries (a browsable discovery entry point).

Columns
name VARCHAR
Short identifier for the recipe (e.g. count_by_type).
kql VARCHAR
The Azure Resource Graph KQL query string β€” pass it straight into resourcegraph_query's first argument.
description VARCHAR
A one-line summary of what the recipe returns.
Example

List every curated KQL recipe with what it returns

SELECT name, description FROM azure.main.kql_recipes ORDER BY name;
Link
Table functions
resourcegraph_query (kql VARCHAR, page_size := BIGINT, subscriptions := VARCHAR) 6 examples

Azure Resource Graph: one KQL query over the ARM estate, returned as one JSON result row per resource. Point-in-time snapshot paginated by an in-scan $skipToken β€” no cross-scan cursor, no change tracking.

Positional arguments
kql VARCHAR
The Azure Resource Graph KQL (Kusto Query Language) query to run, e.g. `'Resources | project name, type, location'`. Required (positional). The query runs across the ARM estate and each returned resource becomes one JSON `result` row.
Named arguments
page_size := BIGINT
ARG page size (options.$top) β€” how many resources ARG returns per internal page. Defaults to 1000, which is also the maximum; larger values are clamped. Paging is transparent (the whole snapshot is returned regardless). Named (page_size := 500). Β· default 1000
subscriptions := VARCHAR
Comma-separated Azure subscription GUIDs to scope the query to, e.g. `'<guid1>,<guid2>'`. Empty (the default) or NULL queries every subscription the service principal can read (ARG scopes by RBAC). Named (subscriptions := '...'). Β· default ""
Returns columns
result VARCHAR
One matching Azure Resource Graph resource serialized as a JSON object string. Extract fields with json_extract(result, '$.<field>') or the -> / ->> operators (e.g. result ->> 'name'). The available JSON fields are whatever the KQL query projects. There is no marker/cursor row β€” every row is a resource.
Examples (6)

First 100 resources as JSON, projecting name, type, and location

SELECT result
FROM azure.main.resourcegraph_query('Resources | project name, type, location')
LIMIT 100;

Count resources by type across the whole estate

SELECT result ->> 'type' AS type, count(*) AS n
FROM azure.main.resourcegraph_query('Resources | project type')
GROUP BY 1
ORDER BY n DESC;

Count resources per subscription by display name: join a Resources count per subscriptionId to the subscription rows of ResourceContainers

WITH subs AS (SELECT result ->> 'subscriptionId' AS subscription_id, result ->> 'name' AS subscription_name FROM azure.main.resourcegraph_query('ResourceContainers | where type =~ ''microsoft.resources/subscriptions'' | project subscriptionId, name')) SELECT s.subscription_name, CAST(r.result ->> 'n' AS BIGINT) AS resources
FROM azure.main.resourcegraph_query('Resources | summarize n = count() by subscriptionId') r
JOIN subs s ON s.subscription_id = r.result ->> 'subscriptionId'
ORDER BY resources DESC, s.subscription_name;
3 more examples

Find resources deployed in a different region than their resource group (global and location-less resources excluded): join Resources to the resource-group rows of ResourceContainers

WITH rgs AS (SELECT result ->> 'subscriptionId' AS subscription_id, lower(result ->> 'name') AS resource_group, result ->> 'location' AS group_location FROM azure.main.resourcegraph_query('ResourceContainers | where type =~ ''microsoft.resources/subscriptions/resourcegroups'' | project subscriptionId, name, location')) SELECT g.resource_group, r.result ->> 'name' AS name, r.result ->> 'type' AS type, r.result ->> 'location' AS location, g.group_location
FROM azure.main.resourcegraph_query('Resources | where isnotempty(location) and location != ''global'' | project name, type, resourceGroup, location, subscriptionId') r
JOIN rgs g ON g.subscription_id = r.result ->> 'subscriptionId' AND g.resource_group = lower(r.result ->> 'resourceGroup')
WHERE r.result ->> 'location' <> g.group_location
ORDER BY g.resource_group, name;

List storage account names alongside their resource group

SELECT result ->> 'name' AS name,
  result ->> 'resourceGroup' AS resource_group
FROM azure.main.resourcegraph_query('Resources | where type =~ ''microsoft.storage/storageaccounts'' | project name, resourceGroup')
ORDER BY name;

Scope the query to one subscription GUID with a 500-resource page size

SELECT result
FROM azure.main.resourcegraph_query('Resources | project name, location', subscriptions := '00000000-0000-0000-0000-000000000000', page_size := 500);
Link

Credentials

The secret type azure declares, as reported by the worker itself.

azure_graph

How to get these credentials

Microsoft Entra app-only (client-credentials) credentials for Azure ARM / Microsoft Graph

secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Key Type Required Description
tenant_id VARCHAR β€” Directory (tenant) ID of the Microsoft Entra tenant, from the app registration's Overview page
client_id VARCHAR β€” Application (client) ID of the Microsoft Entra app registration, from its Overview page
client_secret secret VARCHAR β€” Client secret value created under the app registration's Certificates & secrets page (shown once, at creation)

The worker doesn't mark which keys are required.

Needed by resourcegraph_query

Create the secret in the same session, after attaching azure β€” the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

resourcegraph_bind_probe β€” Bind resourcegraph_query and expose its result column (credential-free; drop LIMIT 0 and attach an azure_graph secret to run the KQL against your estate)

SELECT result
FROM azure.main.resourcegraph_query('Resources | project name, type, location')
LIMIT 0;

Uses resourcegraph_query

Count resources per subscription by display name: join a Resources count per subscriptionId to the subscription rows of ResourceContainers

WITH subs AS (SELECT result ->> 'subscriptionId' AS subscription_id, result ->> 'name' AS subscription_name FROM azure.main.resourcegraph_query('ResourceContainers | where type =~ ''microsoft.resources/subscriptions'' | project subscriptionId, name')) SELECT s.subscription_name, CAST(r.result ->> 'n' AS BIGINT) AS resources
FROM azure.main.resourcegraph_query('Resources | summarize n = count() by subscriptionId') r
JOIN subs s ON s.subscription_id = r.result ->> 'subscriptionId'
ORDER BY resources DESC, s.subscription_name

Uses resourcegraph_query

Find resources deployed in a different region than their resource group (global and location-less resources excluded): join Resources to the resource-group rows of ResourceContainers

WITH rgs AS (SELECT result ->> 'subscriptionId' AS subscription_id, lower(result ->> 'name') AS resource_group, result ->> 'location' AS group_location FROM azure.main.resourcegraph_query('ResourceContainers | where type =~ ''microsoft.resources/subscriptions/resourcegroups'' | project subscriptionId, name, location')) SELECT g.resource_group, r.result ->> 'name' AS name, r.result ->> 'type' AS type, r.result ->> 'location' AS location, g.group_location
FROM azure.main.resourcegraph_query('Resources | where isnotempty(location) and location != ''global'' | project name, type, resourceGroup, location, subscriptionId') r
JOIN rgs g ON g.subscription_id = r.result ->> 'subscriptionId' AND g.resource_group = lower(r.result ->> 'resourceGroup')
WHERE r.result ->> 'location' <> g.group_location
ORDER BY g.resource_group, name

Uses resourcegraph_query

List storage accounts with their resource group

SELECT result ->> 'name' AS name,
  result ->> 'resourceGroup' AS resource_group
FROM azure.main.resourcegraph_query('Resources | where type =~ ''microsoft.storage/storageaccounts'' | project name, resourceGroup')

Uses resourcegraph_query

Query a single subscription by GUID

SELECT result
FROM azure.main.resourcegraph_query('Resources | project name, location', subscriptions := '00000000-0000-0000-0000-000000000000')

Uses resourcegraph_query

List every curated KQL recipe with what it returns

SELECT name, description FROM azure.main.kql_recipes ORDER BY name

Uses kql_recipes

4 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Using Azure Resource Graph, how many resources of each type exist across the estate?
  • List the Azure storage accounts and the resource group each one lives in.
  • Run a Resource Graph query but restrict it to a single subscription GUID.
  • List every Azure storage account together with the display name (not the GUID) of the subscription it belongs to.
  • Before I supply credentials, which ready-made Azure Resource Graph KQL queries can I browse and reuse?

Azure Resource Graph is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.