Draw.io Azure infrastructure diagrams through code like an artist

Draw.io Azure infrastructure diagrams through code like an artist



In this article we will see how to create an Azure diagram to reveal all the dependencies between Azure App Services, their Application Insights and finally their workspace-based Log Analytics Workspaces.


The use case consist in:


  1. auditing the current configuration on Azure through a PowerShell script,
  2. export the current infrastructure set up on a CSV Draw.io readable file,
  3. observe a work of art.







To make this piece of art possible you should have a clear idea of the following concept.


  1. Azure resource dependencies: An App Service or Function App can send logs to an Application Insights and Application Insights can send logs to a Log Analytics workspace. This refers to the concept of Workspace-based Application Insights resources.
  2. Draw.io is a free diagram software that permits to insert diagram from specially formatted CSV Data as explained in the following blog.


We can now move on to the next chapter which consists of creating a script that will scan our Infrastructure and write to the CSV in draw.io format.





The following PowerShell script will analyze your App Services configuration based on which ones have these tags and export its results to a local file.



$AzureTagToFilterOn = @{ "env" = "dev" } $FileForDrawIo = "draw.io.export.txt"



There are 2 main tips on the script you should understand:


  1. The Draw.io “styles” block points out to existing Draw.io shapes, you can print their code by selecting an existing shape, then press Ctrl+E on Windows or Cmd+E on macOS.
  2. You can create multiple connections between your CSV rows with their own properties (labels, line style, etc…).

The complete script:



#region variable $SubscriptionName = "Your Azure Subscription Name" $AzureTagToFilterOn = @{ "env" = "dev" } $FileForDrawIo = "draw.io.export.txt" $DrawIoExport = @() $contentToAdd = @" ## Azure Application Insights depedencies. ## Node label with placeholders and HTML. ## Default is '%name_of_first_column%'. # # label: %name%<br><i style="color:gray;">%type%</i><br> # ## Shapes and their styles # stylename: type # styles: {"application insights": "aspect=fixed;html=1;points=[];align=center;image;fontSize=15;image=img/lib/azure2/management_governance/Application_Insights.svg;",\ # "functionapp": "aspect=fixed;html=1;points=[];align=center;image;fontSize=15;image=img/lib/azure2/iot/Function_Apps.svg;",\ # "log analytics workspaces": "aspect=fixed;html=1;points=[];align=center;image;fontSize=15;image=img/lib/azure2/management_governance/Log_Analytics_Workspaces.svg;",\ # "app": "aspect=fixed;html=1;points=[];align=center;image;fontSize=12;image=img/lib/azure2/app_services/App_Services.svg;"} ## Connections between rows ("from": source colum, "to": target column). ## Label, style and invert are optional. Defaults are '', current style and false. # connect: {"from": "application_insights", "to": "name", "label": "logs", \ # "style": "curved=1;endArrow=blockThin;endFill=1;fontSize=11;"} # connect: {"from": "log_analytics_workspaces", "to": "name", "style": "curved=1;fontSize=11;"} # # ignore: application_insights,log_analytics_workspaces # layout: verticalflow # ## ---- CSV below this line. First line are column names. ---- "@ Set-Content $FileForDrawIo $contentToAdd Add-Content $FileForDrawIo "name,resource_group,type,application_insights,log_analytics_workspaces" #endregion #region function Function draw_io_csv { [CmdletBinding()] Param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true)][String] $name, [Parameter(Mandatory = $true, ValueFromPipeline = $true)][String] $resource_group, [Parameter(Mandatory = $true, ValueFromPipeline = $true)][String] $type, [Parameter(Mandatory = $false, ValueFromPipeline = $true)][String] $application_insights, [Parameter(Mandatory = $false, ValueFromPipeline = $true)][String] $log_analytics_workspaces ) Process { $private:tableObj = New-Object PSObject $tableObj | Add-Member -Name name -MemberType NoteProperty -Value $name $tableObj | Add-Member -Name resource_group -MemberType NoteProperty -Value $resource_group $tableObj | Add-Member -Name type -MemberType NoteProperty -Value $type $tableObj | Add-Member -Name application_insights -MemberType NoteProperty -Value $application_insights $tableObj | Add-Member -Name log_analytics_workspaces -MemberType NoteProperty -Value $log_analytics_workspaces return $tableObj } } #endregion #region action ## connectivity $AzureRmContext = Get-AzSubscription -SubscriptionName $SubscriptionName | Set-AzContext -ErrorAction Stop Select-AzSubscription -Name $SubscriptionName -Context $AzureRmContext -Force -ErrorAction Stop ## audit $ResourceGroups = Get-AzResourceGroup -Tag $AzureTagToFilterOn | Select-Object ResourceGroupName $AllAppInsights = Get-AzResource -ResourceType "microsoft.insights/components" -ExpandProperties foreach ($ResourceGroup in $ResourceGroups) { Write-Host "Working on Resource Group Name [$($ResourceGroup.ResourceGroupName)]" -ForegroundColor Cyan $WebApps = Get-AzWebApp -ResourceGroupName $ResourceGroup.ResourceGroupName | Select-Object ResourceGroup, Name foreach ($WebAppResource in $WebApps) { Write-Host "Working on Web App [$($WebAppResource.Name)]" -ForegroundColor Cyan $WebApp = Get-AzWebApp -ResourceGroupName $WebAppResource.ResourceGroup -Name $WebAppResource.Name $AppInsightsInstrumentationKey = $WebApp.SiteConfig.AppSettings.GetEnumerator() | Where-Object {$_.name -eq "APPINSIGHTS_INSTRUMENTATIONKEY"} $AppInsightsProperties = $AllAppInsights | Select-Object -ExpandProperty Properties | Select-Object Name, InstrumentationKey, WorkspaceResourceId | Where-Object {$_.InstrumentationKey -eq $AppInsightsInstrumentationKey.Value} if($AppInsightsProperties) { if($AppInsightsProperties.WorkspaceResourceId) { Write-Host "Export the configuration of the Log Analytics Workspace [$($AppInsightsProperties.WorkspaceResourceId.split("/")[-1])] connected to the App [$($WebAppResource.Name)]" $LogAnalyticsWorkspacesName = $AppInsightsProperties.WorkspaceResourceId.split("/")[-1] $DrawIoExport += draw_io_csv -name $AppInsightsProperties.WorkspaceResourceId.split("/")[-1] ` -resource_group $AppInsightsProperties.WorkspaceResourceId.split("/")[-5] ` -type "log analytics workspaces" ` -application_insights "" ` -log_analytics_workspaces "" }else{ $LogAnalyticsWorkspacesName = "" } $AppInsightsId = $($AllAppInsights | Where-Object {$_.Name -like $AppInsightsProperties.Name}).Id $AppInsightsName = $($AppInsightsId.Split("/")[-1]) Write-Host "Export the configuration of the Application Insights [$($AppInsightsId.split("/")[-1])] connected to the App [$($WebAppResource.Name)]" $DrawIoExport += draw_io_csv -name $AppInsightsId.split("/")[-1] ` -resource_group $AppInsightsId.split("/")[-5] ` -type "application insights" ` -application_insights "" ` -log_analytics_workspaces $LogAnalyticsWorkspacesName }else{ $AppInsightsName = "" } Write-Host "Export the configuration of the App [$($WebAppResource.Name)]" $DrawIoExport += draw_io_csv -name $WebApp.Name ` -resource_group $WebApp.ResourceGroup ` -type $WebApp.Kind.Split(",")[0] ` -application_insights $AppInsightsName ` -log_analytics_workspaces "" } } #endregion #region export foreach($Line in $DrawIoExport | Select-Object -Unique -Property name, resource_group, type, application_insights, log_analytics_workspaces){ Add-Content $FileForDrawIo "$($Line.name),$($Line.resource_group),$($Line.type),$($Line.application_insights),$($Line.log_analytics_workspaces)".ToLower() } #endregion






From Draw.io select Arrange > Insert > Advanced > CSV.






Paste your formatting information and CSV data into the large text field, overwriting the example.





The following screenshot illustrates a diagram generated by the PowerShell script.







We saw in this demo how to draw a script-based Azure App Service oriented diagram. This methodology has no limits and DALL-E knows it, would you defeat it ?


See You in the Cloud


Published on:

Learn more
Azure Developer Community Blog articles
Azure Developer Community Blog articles

Azure Developer Community Blog articles

Share post:

Related posts

Azure VMware Solution using a public IP down to the NSX-T Edge; configure SNAT, No-SNAT & DNAT

Azure VMware Solution How To Series: Configuring NSX-T SNAT, No-SNAT & DNAT rules   Overview Requirements Lab Environment NAT Rules K...

6 hours ago

App attach for Azure Virtual Desktop now generally available

App attach for Azure Virtual Desktop allows IT admins to dynamically attach applications from an application package to a user session in Azur...

1 day ago

A Closer Look at Azure WAF’s Data Masking Capabilities for Azure Front Door

The Azure Web Application Firewall (WAF) on Azure Front Door offers centralized protection for your web applications against vulnerabilities a...

1 day ago

Azure Virtual Network Manager (AVNM) Mesh and Direct Connectivity are Generally Available!

Azure Virtual Network Manager's (AVNM) mesh connectivity configuration and direct connectivity option in the hub and spoke connectivity config...

1 day ago

Azure pricing: How to calculate costs of Azure products and services

In our previous blogs we explained the Azure pricing structure and how customers can estimate their project costs when migrating to Azure or b...

1 day ago

Azure Pricing: How to estimate Azure project costs

In the previous blog we explained how you can learn about Azure pricing with free services and a pay-as-you-go model. Next, lets understand ho...

1 day ago

Azure Pricing: How to navigate Azure pricing options and resources

In this blog we discussed customer pricing needs and how they match different phases of the cloud journey, and we provided various tools and r...

1 day ago

Azure pricing: How to optimize costs for your Azure workloads

In our previous blogs we explained the Azure pricing structure, how customers can calculate their costs when migrating or building in Azure, a...

1 day ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy