A repository for Azure Resource Graph with focus on creating and running queries using Azure PowerShell and Azure CLI with local VS Code support.
This purpose of this repository is two-fold - to serve as a reference repository for myself and others while working with Azure Resource Graph - and to share own content related to Azure Resource Graph.
Tip
With the work in this repository I am aiming at producing a series of blog posts on my personal blog. To get notice of posts you can subscribe to the site RSS feed or follow updates in this repository.
The current goal is to produce the following posts to companion this repository (items without links are not published yet):
- Why Azure Resource Graph
- Basic KQL and Resource Graph Queries
- Advanced Resource Graph Queries
- Sharing Resource Graph Queries in Azure
- Automating Resource Graph Queries
Disclaimer: This might be subject to change as I go along. No dates for publishing promised 😉
- Azure Resource Graph is an Azure service that provides a performant queryable interface to Azure across your subscriptions
- The query language is based on Kusto Query Language (KQL)
The knowledge of resource graph and KQL is an extremely powerful skill-set when working with Azure and can be utilized to work with governance (logs, alerts, monitoring) and Governance (workbooks, assessments, change analysis, reporting) among other things.
For an introduction to KQL basics in Azure I recommend the MS Learn learning path here.
The following prerequisites are recommended to get started with using the code provided in this repository.
- VS Code
- Install recommended extensions
- Azure PowerShell
- Azure CLI
- Reader role in your Azure environment
Note
Azure Resource Graph does not require Azure CLI and Azure PowerShell. Based on what you're used to and what you are working with you can choose what to use. Both tools work on all platforms. From my side my main tool is Azure PowerShell (running on Linux! 🐧) as I like the object-based, structured output it offers.
# Login
Connect-AzAccount
# Install module
Install-Module -Name Az.ResourceGraph
# In-line query
Search-AzGraph -Query 'Resources | project name, type | limit 5'
# Query from file
$query = Get-Content -Path <file> -Raw
Search-AzGraph -Query $query
See more details here.
# Login
az login
# Install extension
az extension add --name resource-graph
# In-line query
az graph query -q 'Resources | project name, type | limit 5'
# Query from file
QUERY=$(cat <file>)
az graph query -q "$QUERY"
# Query from file using script with formatted output
./scripts/resource-graph-query.sh <file>
./scripts/resource-graph-query.sh queries/resources/resource-type-count.kql # example
See more details here.