Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JayDoubleu/67a23ab137f51adac05d8b0a76ef56d7 to your computer and use it in GitHub Desktop.
Save JayDoubleu/67a23ab137f51adac05d8b0a76ef56d7 to your computer and use it in GitHub Desktop.
Export-AzFrontDooRoutingRuleRoutes
<#
.SYNOPSIS
Returns all permutations of paths through the front door object to the target backends configured.
.DESCRIPTION
For the provided Azure Front Door resource, this function generates output objects for each permutation of:
* Url input
* Pattern Matched
* Custom Path Mapping
* Target backend
A routing rule can be mapped to N front end urls, N patterns and a single backend.
A backend may have multiple backend addresses.
The routing rule may also perform a custom forwarding path (URL rewrite).
This means, for a single routing rule, mapped to two front end urls, with 3 matching patterns and
a backend pool that has 6 addresses, this function will generate 36 output objects for each
combination of the 3 variables.
As a routing rule can only specify a single Custom Forward Path, it is either included or blank for all outputs.
.PARAMETER InputObject
An Azure Front Door object
.INPUTS
Microsoft.Azure.Commands.FrontDoor.Models.PSFrontDoor
.OUTPUTS
PSCustomObject
.EXAMPLE
PS> Get-AzFrontDoor -Name <name> | Export-AzFrontDoorRoutingRuleRoutes | Format-Table -Autosize
.EXAMPLE
PS> Get-AzFrontDoor -Name <name> | Export-AzFrontDoorRoutingRuleRoutes | Export-Csv -Path <path>
.LINK
https://docs.microsoft.com/en-us/powershell/module/az.frontdoor/get-azfrontdoor?view=azps-7.2.0
.LINK
Get-AzFrontDoor
#>
function Export-AzFrontDooRoutingRuleRoutes {
[cmdletbinding()]
param(
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
[Microsoft.Azure.Commands.FrontDoor.Models.PSFrontDoor]$InputObject
)
process {
$inputObject.RoutingRules | ForEach-Object {
$routingRule = $_
# Get the backend pool as there is only one of them
$backendPoolName = ($routingRule.RouteConfiguration.BackendPoolId -split "/")[-1]
$backendPool = $inputObject.BackendPools | Where-Object Name -eq $backendPoolName
# Get all the addresses associated with the backend
$backendAddresses = $backendPool.Backends | Select-Object -ExpandProperty Address
# Get all the urls that this routing rule is associated with
$frontEndUrls = $routingRule.FrontendEndpointIds | ForEach-Object {
$inputObject.FrontendEndpoints | Where-Object Name -eq ($_ -split "/")[-1] `
| Select-Object -ExpandProperty HostName
}
# Create a single output which is a unique route based on
# input hostname
# pattern matched
# backend address
$routingRule.PatternsToMatch | ForEach-Object {
$pattern = $_
$backendAddresses | ForEach-Object {
$backendAddress = $_
$frontEndUrls | ForEach-Object {
$outputObject = [pscustomobject]@{
FrontDoorName = $inputObject.Name
FrontEndUrl = $_
PathPattern = $pattern
CustomForwardPath = $routingRule.RouteConfiguration.CustomForwardingPath
RoutingRuleName = $routingRule.name
BackendName = $backendPool.Name
Target = $backendAddress
}
Write-Output $outputObject
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment