|
1 | 1 | --- |
2 | 2 | title: "Resource Graph" |
3 | | -description: API coverage for Microsoft.ResourceGraph in LocalStack for Azure. |
| 3 | +description: Get started with Azure Resource Graph on LocalStack |
4 | 4 | template: doc |
5 | 5 | --- |
6 | 6 |
|
7 | 7 | import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureFeatureCoverage"; |
8 | 8 |
|
| 9 | +## Introduction |
| 10 | + |
| 11 | +Azure Resource Graph is a service for querying Azure resources at scale using a structured query language. |
| 12 | +It helps you search, filter, and project resource metadata across subscriptions. |
| 13 | +Resource Graph is useful for inventory, governance checks, and automated analysis workflows. |
| 14 | + |
| 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. |
| 17 | + |
| 18 | +## Getting started |
| 19 | + |
| 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 | + |
| 22 | +Start your LocalStack container using your preferred method. |
| 23 | +Then start CLI interception: |
| 24 | + |
| 25 | +```bash |
| 26 | +azlocal start_interception |
| 27 | +``` |
| 28 | + |
| 29 | +### Create a resource group |
| 30 | + |
| 31 | +Create a resource group for the resources you want to query: |
| 32 | + |
| 33 | +```bash |
| 34 | +az group create \ |
| 35 | + --name rg-resourcegraph-demo \ |
| 36 | + --location westeurope |
| 37 | +``` |
| 38 | + |
| 39 | +```bash title="Output" |
| 40 | +{ |
| 41 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-resourcegraph-demo", |
| 42 | + "location": "westeurope", |
| 43 | + "managedBy": null, |
| 44 | + "name": "rg-resourcegraph-demo", |
| 45 | + "properties": { |
| 46 | + "provisioningState": "Succeeded" |
| 47 | + }, |
| 48 | + "tags": null, |
| 49 | + "type": "Microsoft.Resources/resourceGroups" |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +### Create sample web resources |
| 54 | + |
| 55 | +Create an App Service plan and a Web App, which we will query using Resource Graph: |
| 56 | + |
| 57 | +```bash |
| 58 | +az appservice plan create \ |
| 59 | + --name asp-doc81 \ |
| 60 | + --resource-group rg-resourcegraph-demo \ |
| 61 | + --location westeurope \ |
| 62 | + --sku F1 |
| 63 | + |
| 64 | +az webapp create \ |
| 65 | + --name ls-app-doc81 \ |
| 66 | + --resource-group rg-resourcegraph-demo \ |
| 67 | + --plan asp-doc81 \ |
| 68 | + --runtime "PYTHON:3.11" |
| 69 | +``` |
| 70 | + |
| 71 | +```bash title="Output" |
| 72 | +{ |
| 73 | + "asyncScalingEnabled": false, |
| 74 | + "elasticScaleEnabled": false, |
| 75 | + "geoRegion": "West Europe", |
| 76 | + "hyperV": false, |
| 77 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-resourcegraph-demo/providers/Microsoft.Web/serverfarms/asp-doc81", |
| 78 | + ... |
| 79 | + "name": "asp-doc81", |
| 80 | + ... |
| 81 | + "status": "Ready", |
| 82 | + "subscription": "00000000-0000-0000-0000-000000000000", |
| 83 | + ... |
| 84 | +} |
| 85 | +{ |
| 86 | + ... |
| 87 | + "enabledHostNames": [ |
| 88 | + "ls-app-doc81.azurewebsites.net", |
| 89 | + "ls-app-doc81.scm.azurewebsites.net" |
| 90 | + ], |
| 91 | + ... |
| 92 | + "hostNameSslStates": [ |
| 93 | + { |
| 94 | + "hostType": "Standard", |
| 95 | + "name": "ls-app-doc81.azurewebsites.net", |
| 96 | + "sslState": "Disabled", |
| 97 | + "thumbprint": null, |
| 98 | + "toUpdate": null, |
| 99 | + "virtualIp": null |
| 100 | + }, |
| 101 | + ... |
| 102 | + ], |
| 103 | + "hostNames": [ |
| 104 | + "ls-app-doc81.azurewebsites.net" |
| 105 | + ], |
| 106 | + ... |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +### Query resources with Resource Graph |
| 111 | + |
| 112 | +The following queries mirror the same patterns used in our validated tests: |
| 113 | + |
| 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` |
| 118 | + |
| 119 | +For example, run a query for all web sites: |
| 120 | + |
| 121 | +```bash |
| 122 | +az rest --method post \ |
| 123 | + --url "http://management.localhost.localstack.cloud:4566/providers/Microsoft.ResourceGraph/resources?api-version=2021-03-01" \ |
| 124 | + --headers "Content-Type=application/json" \ |
| 125 | + --body "{\"subscriptions\":[\"00000000-0000-0000-0000-000000000000\"],\"query\":\"where type =~ 'Microsoft.Web/sites'\"}" |
| 126 | +``` |
| 127 | + |
| 128 | +```bash title="Output" |
| 129 | +{ |
| 130 | + "count": 1, |
| 131 | + "data": { |
| 132 | + "columns": [ |
| 133 | + { |
| 134 | + "name": "id", |
| 135 | + "type": "string" |
| 136 | + }, |
| 137 | + { |
| 138 | + "name": "name", |
| 139 | + "type": "string" |
| 140 | + }, |
| 141 | + ... |
| 142 | + ], |
| 143 | + "rows": [ |
| 144 | + [ |
| 145 | + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-resourcegraph-demo/providers/Microsoft.Web/sites/ls-app-doc81", |
| 146 | + "ls-app-doc81", |
| 147 | + "westeurope", |
| 148 | + ... |
| 149 | + ] |
| 150 | + ] |
| 151 | + }, |
| 152 | + ... |
| 153 | + "totalRecords": 1 |
| 154 | +} |
| 155 | +``` |
| 156 | + |
| 157 | +Or, run a query for an unknown resource name: |
| 158 | + |
| 159 | +```bash |
| 160 | +az rest --method post \ |
| 161 | + --url "http://management.localhost.localstack.cloud:4566/providers/Microsoft.ResourceGraph/resources?api-version=2021-03-01" \ |
| 162 | + --headers "Content-Type=application/json" \ |
| 163 | + --body "{\"subscriptions\":[\"00000000-0000-0000-0000-000000000000\"],\"query\":\"where type =~ 'Microsoft.Web/sites' and name =~ 'doesnotexist'\"}" |
| 164 | +``` |
| 165 | + |
| 166 | +```bash title="Output" |
| 167 | +{ |
| 168 | + "count": 0, |
| 169 | + "facets": [], |
| 170 | + "resultTruncated": "false", |
| 171 | + "totalRecords": 0 |
| 172 | +} |
| 173 | +``` |
| 174 | + |
9 | 175 | ## API Coverage |
10 | 176 |
|
11 | 177 | <AzureFeatureCoverage service="Microsoft.ResourceGraph" client:load /> |
0 commit comments