You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -11,21 +11,29 @@ import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureF
11
11
Azure Resource Graph is a service for querying Azure resources at scale using a structured query language.
12
12
It helps you search, filter, and project resource metadata across subscriptions.
13
13
Resource Graph is useful for inventory, governance checks, and automated analysis workflows.
14
+
For more information, see [Azure Resource Graph overview](https://learn.microsoft.com/en-us/azure/governance/resource-graph/overview).
14
15
15
-
LocalStack for Azure allows you to build and test Resource Graph workflows in your local environment.
16
-
The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of Resource Graph's integration with LocalStack.
16
+
LocalStack for Azure enables users to explore resources deployed within the local environment using [Kusto Query Language (KQL)](https://learn.microsoft.com/en-us/azure/governance/resource-graph/concepts/query-language#supported-tabulartop-level-operators).
17
17
18
18
## Getting started
19
19
20
20
This guide is designed for users new to Resource Graph and assumes basic knowledge of the Azure CLI and our `azlocal` wrapper script.
21
21
22
-
Start your LocalStack container using your preferred method.
23
-
Then start CLI interception:
22
+
Launch LocalStack using your preferred method. For more information, see [Introduction to LocalStack for Azure](/azure/getting-started/). Once the container is running, enable Azure CLI interception by running:
24
23
25
24
```bash
26
-
azlocal start_interception
25
+
azlocal start-interception
27
26
```
28
27
28
+
This command points the `az` CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API.
29
+
To revert this configuration, run:
30
+
31
+
```bash
32
+
azlocal stop-interception
33
+
```
34
+
35
+
This reconfigures the `az` CLI to send commands to the official Azure management REST API.
36
+
29
37
### Create a resource group
30
38
31
39
Create a resource group for the resources you want to query:
@@ -109,69 +117,185 @@ az webapp create \
109
117
110
118
### Query resources with Resource Graph
111
119
112
-
The following queries mirror the same patterns used in our validated tests:
120
+
The Resource Graph extension must be installed to use `az graph` commands. Refer to the [official installation instructions](https://learn.microsoft.com/en-us/azure/governance/resource-graph/first-query-azurecli#install-the-extension). Use the [az graph query](https://learn.microsoft.com/en-us/cli/azure/graph?view=azure-cli-latest#az-graph-query) command to run Kusto Query language (KQL) queries against the emulator.
121
+
The following examples demonstrate common query patterns:
113
122
114
-
- filter by type: `where type =~ 'Microsoft.Web/sites'`
115
-
- filter by type and name: `where type =~ 'Microsoft.Web/sites' and name =~ 'ls-app-doc81'`
116
-
- filter by name: `where name =~ 'ls-app-doc81'`
117
-
- project only IDs: `where type =~ 'Microsoft.Web/sites' and name =~ 'ls-app-doc81' | project id`
123
+
```bash
124
+
az graph query \
125
+
--graph-query "Resources | where type =~ 'Microsoft.Web/sites'"
--graph-query "Resources | where resourceGroup =~ 'rg-resourcegraph-demo' | count"
173
+
```
174
+
175
+
```bash title="Output"
176
+
{
177
+
"count": 1,
178
+
"data": [
179
+
{
180
+
"Count": 2
181
+
}
182
+
],
183
+
"skip_token": null,
184
+
"total_records": 1
154
185
}
155
186
```
156
187
157
-
Or, run a query for an unknown resource name:
188
+
List resources sorted by name with a row limit:
189
+
190
+
```bash
191
+
az graph query \
192
+
--graph-query "Resources | where resourceGroup =~ 'rg-resourcegraph-demo' | project name, type | order by name asc | limit 5"
193
+
```
194
+
195
+
```bash title="Output"
196
+
{
197
+
"count": 2,
198
+
"data": [
199
+
{
200
+
"name": "asp-doc81",
201
+
"type": "Microsoft.Web/serverfarms"
202
+
},
203
+
{
204
+
"name": "ls-app-doc81",
205
+
"type": "Microsoft.Web/sites"
206
+
}
207
+
],
208
+
"skip_token": null,
209
+
"total_records": 2
210
+
}
211
+
```
212
+
213
+
Query a resource that does not exist:
214
+
215
+
```bash
216
+
az graph query \
217
+
--graph-query "Resources | where type =~ 'Microsoft.Web/sites' and name =~ 'doesnotexist'"
218
+
```
219
+
220
+
```bash title="Output"
221
+
{
222
+
"count": 0,
223
+
"data": [],
224
+
"skip_token": null,
225
+
"total_records": 0
226
+
}
227
+
```
228
+
229
+
### Query resources with the REST API
230
+
231
+
An alternative way to invoke Azure Resource Graph is to call its REST API directly using the [`az rest`](https://learn.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest#az-rest) command:
The Resource Graph emulator supports the following features:
263
+
264
+
-**KQL query engine**: A built-in parser and executor for the Kusto Query Language (KQL) subset used by Azure Resource Graph.
265
+
-**Tabular and object result formats**: The `resultFormat` option controls whether results are returned as a column/row table or as an array of objects.
-**Comparison operators**: Full support for `==`, `!=`, `=~`, `!~`, `contains`, `!contains`, `contains_cs`, `!contains_cs`, `startswith`, `!startswith`, `endswith`, `!endswith`, `has`, `!has`, `in`, `!in`, and `matches regex`.
268
+
-**Aggregate functions**: `count()`, `dcount()`, `countif()`, `sum()`, `sumif()`, `avg()`, `min()`, and `max()` for use in `summarize` stages.
269
+
270
+
## Limitations
271
+
272
+
-**Single table only**: The emulator queries the `Resources` table. Other Resource Graph tables (such as `ResourceContainers`, `AdvisorResources`, and `SecurityResources`) are not available.
273
+
-**No data persistence across restarts**: Resource metadata is not persisted and is lost when the LocalStack emulator is stopped or restarted.
274
+
275
+
### Supported tabular operators
276
+
277
+
The table below lists the KQL tabular operators supported by Azure Resource Graph and their availability in the LocalStack emulator.
278
+
For the full reference, see [Supported tabular/top-level operators](https://learn.microsoft.com/en-us/azure/governance/resource-graph/concepts/query-language#supported-tabulartop-level-operators).
279
+
280
+
| Operator | Supported | Notes |
281
+
|---|---|---|
282
+
|`count`| Yes | Returns a single row with the total number of input rows. |
283
+
|`distinct`| Yes | Deduplicates rows by the specified columns. |
284
+
|`extend`| Yes | Adds computed columns to the result set. |
285
+
|`join`| No | Cross-table joins are not supported. The emulator does not implement `ResourceContainers` or other secondary tables. |
286
+
|`limit`| Yes | Synonym of `take`. |
287
+
|`mv-expand`| No | Array expansion into multiple rows is not supported. |
288
+
|`order`| Yes | Synonym of `sort`. Supports `asc` and `desc` directions. |
289
+
|`parse`| No | String parsing with pattern matching is not supported. |
290
+
|`project`| Yes | Supports column selection and aliased expressions. |
291
+
|`project-away`| Yes | Removes specified columns from the result set. |
292
+
|`sort`| Yes | Synonym of `order`. |
293
+
|`summarize`| Yes | Supports aggregate functions with an optional `by` clause. |
294
+
|`take`| Yes | Synonym of `limit`. |
295
+
|`top`| Yes | Returns the first N rows sorted by specified columns. |
296
+
|`union`| No | Combining results from multiple tables is not supported. |
297
+
|`where`| Yes | Filters rows using comparison, logical, and string operators. |
0 commit comments