By Shamim Raashid, Rahul Shettigar, and Vignesh Ramakrishnan
Creating a mesh network across multiple Virtual Private Clouds (VPCs) is a powerful way to ensure seamless communication between your cloud resources while maintaining isolation and security. A VPC mesh network is a network topology where every VPC is connected to every other VPC, creating direct paths between all of them. This kind of setup is ideal for complex architectures, where you need high availability, fault tolerance, and low-latency communication across multiple VPCs.
In this tutorial, we will walk you through using a Bash script to automate the process of creating a VPC mesh network on DigitalOcean. The script simplifies the management of VPCs and peerings, which will allow you to:
jq
to parse JSON responses from the DigitalOcean API. Ensure it’s installed on your machine.You can install jq
using the following commands:
On Ubuntu/Debian:
On CentOS/RedHat:
To use the script, first download the script to your server or local machine using the following command:
Then, grant execution permissions and run the script
When prompted, enter your DigitalOcean API token to authenticate the script.
You’ll be presented a menu with the following options:
The script first checks if the provided DigitalOcean API token is valid by querying the DigitalOcean API for the list of VPCs. If the token is invalid, the script will terminate with an error message.
This function retrieves and lists all VPCs associated with your DigitalOcean account. It displays the following details:
The list is formatted into a clean, dynamic table with columns that adjust based on the length of VPC IDs and names.
This function retrieves and displays all existing VPC peerings in your account. The output includes:
This helps you track which VPCs are already connected and avoid creating duplicate peerings.
This is the main function of the script, allowing you to create new VPC peerings between selected VPCs. The script performs the following steps:
After creating the peerings, the script will clean up any temporary files and return to the main menu.
List VPCs: When you select option 1 to list VPCs, the output might look like this:
List VPC Peerings: Selecting option 2 to view existing peerings will display something like this:
Create VPC Peerings: Selecting option 3 will prompt you to select VPCs for peering. For example:
This script provides a simple and efficient way to manage VPC peerings within your DigitalOcean infrastructure, making it easier to build and maintain a mesh network of interconnected VPCs. By automating the process of listing, managing, and creating VPC peerings, the script helps streamline VPC configuration tasks, saving you time and reducing the likelihood of errors.
With this tool, you can:
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!