Dave's little Spot on the net

  • About
  • Blog

Synchronise Azure Route Table from Az BGP or text file source

Posted by David Roitman on October 24, 2020
Posted in: Azure, Script.

Continuing on from my previous post, I updated that script a little and also developed a new augmented version to synchronise an external list of CIDR prefixes either directly from Azure BGP ranges or a text file.

Script located on Github at https://github.com/roity57/Azure-Gather-and-Compare-Info/blob/master/AzRouteTableSync.ps1

The script is designed to read in the source list of CIDR Prefixes in the format of one prefix per line EG: 13.77.0.0/24. It will check the destination Route Table to see if any of the source list prefixes are new, and if so it will add them in. Then it will do another pass to see if there are Route Table entries that don’t exist in the source list and if so, it will remove the Route Table entries. The specific use case is maintaining a single Azure Route Table in a subscription maintained in sync dynamically with an external source, it’s not for maintaining a Route Table in sync with multiple dynamic sources. If you want to use it for this use case, then the various sources would need to be amalgamated into a single source via another script of somesort, so you could stage the input source first – I might do this as one of my next exercises 😉

If a BGP community is used then the process is as follows:

  1. If BGP Name specified
    • Fetch the desired BGP table CIDR prefixes from Azure
    • Fetch the actual BGP number details such as 12076:51016
    • prepare the route name format.
  2. If Not BGP route table, read CIDR list from specified text file
  3. Fetch the Azure Subscription Route Table
  4. Extract the Address Prefixes specifically
  5. Foreach loop BGP or file sourced list of prefxies;
    • Assemble remainder of route table name entry
    • Array “-contains” search if the route already exists and record boolean result
    • If boolean result False, add route to route table configuration variable
  6. Foreach Cycle through the Routes in the Route Table in Azure
    • Array “-contains” search if the route exists in the source and record boolean result
    • If boolean result False, remove the route table entry from configuration variable
  7. Once the list has been cycled, commit the new routes to Azure. If the commit to Azure fails then Azure will report an error and the script will also notify.

I previously used a nested foreach loop to search through the source list the script ingests but simplified this by replacing it with the use of the “-contains” parameter on the array.

Posts navigation

← Bulk create route table User Defined Routes
Export Azure DNS Zones →
  • Recent Posts

    • Secure Cross-region load-balanced Server deployment
    • Extract Azure Logs
    • Basic AZ Subnet Listing
    • Export Azure DNS Zones
    • Synchronise Azure Route Table from Az BGP or text file source
  • Categories

  • Archives

    • May 2023
    • July 2022
    • September 2021
    • October 2020
    • August 2020
    • July 2020
    • June 2020
Proudly powered by WordPress Theme: Parament by Automattic.