There are 3 different ways you can create virtual networks in Microsoft azure which is classic mode of created using old azure portal (using method like https://github.com/mani0070/AzureAutomation/blob/master/azureinfrastructureascode/AzureVNetSetup.ps1), 2) using Azure resource manager PowerShell and 3) Azure resource manager templates. In this blogpost we are going to look at using Azure resource manager template and PowerShell to provision the virtual networks and configure gateway.
Pre-requisites for this article is Microsoft Azure subscription and assumptions are you selected the appropriate subscription then switched to azure resource manager mode. Sometime it’s really confusion to switch between different modes, but soon I think it might be easier when azure V2 is fully operational, coming out of preview mode.
The requirement here is to create a Virtual network named “DiDevNetwork” under the resource group call DiLtdMaster for the development team to operate their services, next the testing team who needs a DiLtdTest resource group and “DiTestNetwork” to deploy the services and run the test all kinds of test in their own space. This means you need a Gateways and VPN connection between two networks (DiLtdMaster and DiLtdTest) to deploy code and run required tests. The key here to this process is make this task is repeatable in idempotent manner.
So, let’s get started in creating the Dev network
- Create a Virtual Network named “DiDevNetwork” (Address Prefix : 10.1.0.0/16)
- Create two Subnet named “SubnetGateway” ( 10.1.0.0/24) and “FrontEnd” ( 10.1.1.0/24)
- Obtain a Public Gateway IP Address
- Create a VnetGateway IP configuration
- Create a Virtual Network Gateway
The first part of virtual network is created using the Azure resource manager PowerShell as shown below.
Once the above PowerShell is successfully completed. You can see the network in the preview portal as shown below
Now, let’s go ahead and create a test team virtual network and gateway using the ARM Templates
- Create a Virtual Network named “DiTestNetwork” (Address Prefix : 10.2.0.0/16)
- Create two Subnet named “SubnetGateway” ( 10.2.0.0/24) and “FrontEnd” ( 10.2.1.0/24)
- Obtain a Public Gateway IP Address
- Create a VnetGateway IP configuration
- Create a Virtual Network Gateway
Following are in different resources in ARM Template
Follow are the parameters.json file
Ref : https://github.com/Azure/azure-quickstart-templates
Below is the JSON outline
Below is the command to create the resource group and apply the template with appropriate parameters file to provision the resources.
Once the ARM template have been applied, you can view the networks in the Azure preview portal as shown below
Once we have the Gateway created for both the network, now we are in a positon to create the VPN Connection for both the vNets to talk to each other using Azure resource manager PowerShell.