Skip to content

This Python script is used to interact with the Microsoft Azure Resource Graph service to query Azure Resource Manager for information on Azure resources.

License

Notifications You must be signed in to change notification settings

mattfeltonma/query-azure-resource-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Microsoft Azure Resource Graph Query

This Python script is used to interact with the Microsoft Azure Resource Graph service to query Azure Resource Manager for information on Azure resources. It is written using Python 3.6.

What problem does this solve?

Retrieving information about Azure resources typically involves creating separate resource queries to each resource provider such as storage, network, and compute. By using the Microsoft Azure Resource Graph queries for properties of resources can be performed without having to make them individually to each resource provider. The service also supports complex queries using the Resource Graph query language.

Requirements

Setup

Clone the repository.

Install the required modules referenced above.

Prior to running the script you will need to create the Azure Active Directory security principal that the script will use. The script uses the OAuth 2.0 Client Credential Grant flow to acquire an OAuth token to access the Resource Graph. The security principal needs to be granted the permission to access the Resource Graph and have the appropriate RBAC role over the subscription you plan to query. See the following Microsoft documentation for instructions.

The script logs to standard output by default and can additionally be configured to write the log to a file.

The results of the query are stored in JSON format in a file with a filename specified by the user at runtime. This can be imported into a business intelligence tool such as PowerBI for further analysis. The query must use the Resource Graph query language.

The Resource Graph is configured to page results if more than 100 records are returned. The script is configured to handle these paged records and will write the records to the file after all of the returned records have been retrieved.

Execution

The script requires a parameters file and a filename for the export file be provided as arguments at runtime. A sample parameters file is included in the repository.

Example: python3 azure-inventory.py --parameterfile parameters.json --exportfile resources.json [--logfile query.log]

About

This Python script is used to interact with the Microsoft Azure Resource Graph service to query Azure Resource Manager for information on Azure resources.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages