Skip to main content

Export your Azure Infrastructure as an SVG with AzViz

· 2 min read
Drew Robson

A picture is worth a thousand words.

Software development is a team sport, so any tool or process which helps individuals communicate better will improve the team’s performance. Images are an easy way to cut through confusion, but it can be difficult to get a visual representation of your Azure Infrastructure. Providing this visual representation is very helpful in presenting or analysing your current state infrastructure, so here’s an easy way to generate it via a command line tool.

Azure Visualizer, aka ‘AzViz’ is a PowerShell module which automatically generates Azure resource topology diagrams as an SVG.

Here is my current Resource Group as seen in the Azure Portal:

alt text

Now to generate a diagram of it.

Install Graphviz

Install Graphviz via Chocolately. This is a dependency for AzViz.

# Install chocolatey package Graphviz for Windows
choco install graphviz

Install PowerShell Module

Install the AzViz PowerShell Module in your PowerShell terminal.

# Install the base Az module
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

# Install from powershell gallery
Install-Module -Name AzViz -Scope CurrentUser -Repository PSGallery -Force

# Import the module
Import-Module AzViz

Execute PowerShell Module

Save the following code as azviz-svg.ps1 in your working directory.

# Clear account
Clear-AzContext

# Get input parameters
$tenentId = $args[0]
$subscription = $args[1]

# Connect to account
Connect-AzAccount -TenantId $tenentId -Subscription $subscription
Import-Module AzViz

# Set context to your Azure Tenant
Set-AzContext -TenantId $tenentId

Get-AzSubscription -TenantId $tenentId | Select-Object -Property Name, SubscriptionId -OutVariable directory

ForEach($s in $directory)
{
# Put subscription in context
Select-AzSubscription -SubscriptionId $s.SubscriptionId
ForEach($rg in Get-AzResourceGroup)
{
# Get resource group name
$rgn = $rg.ResourceGroupName

# Generate diagram
Export-AzViz -ResourceGroup $rg.ResourceGroupName -Theme light -OutputFormat svg -OutputFilePath "./$rgn.svg" -LabelVerbosity 2 -CategoryDepth 1
}
}

Then execute it with your Azure Tenant ID and Subscription ID.

# Execute
./azviz-svg.ps1 $tenantId $subscriptionId

f successful, the output will look like:

alt text

The Result

From the above, an SVG diagram per Resource Group will be generated. This can now be shared with the team or stakeholders for further analysis or discussion.

alt text