The last month or so has been packed with announcements and training! I’ve been to Ignite in Atlanta, as well as some internal training and some fun community events. Finally, I’ve had some time to sit down and work on trying out a few things. If you missed the announcement around Ignite time, Azure VNET Peering is now generally available. With peering, you can now link virtual networks together without having to set up multiple VNET gateways.
This peering feature can be set up using the Azure Portal, but what fun is that, right? Let’s do it with some ARM templates instead. My goal was to create two VNETs with different address spaces (you can’t peer networks with an overlapping address space) then peer them together. I could do this with one big template, but I wanted to also take some time to try out linking templates together – where one parent template calls others. I also wanted to take advantage of parameters files to create the different VNETs.
For this example, I ended up with five JSON files:
- azuredeploy.json – The deployment template for one VNET
- vnet1.parameters.json – The parameters file for VNET1
- vnet2.parameters.json – The parameters file for VNET2
- peeringdeploy.json – Template to peer together the networks once created
- parentdeploy.json – The template used to manage the complete deployment
Within the parentdeploy.json file we only need to define the schema and resources sections and the only resource I’m calling is the “Microsoft.Resources/deployments” type. Within that, you’ll need to define a name, mode, template link (located in a repo or blob storage) and an optional parameters link. For this deployment, I’m calling the deployment resource three times – once for each vnet, plus a final time to peer them. In the snippet below, you can see that I called the azuredeploy.json file and the vnet1.parameters.json file.
The second resource uses the same template link and uses the vnet2.parameters.json file. Finally, the last one will only call the peeringdeploy.json template with no parameters file needed. Each deployment resource needs it’s own unique name and you can’t reference anything directly that isn’t included in the template itself. There are also ways to share state between linked templates to be even more “elegant” in your template creation.
Within the peeringdeploy.json template we also only need to define resources which link the newly created VNETs together. In the snippet below, you can see BigNetA (created with vnet1 parameters) being connected to BigNetB (created with vnet2 parameters).
Finally, as with all my previous templates, I can deploy the whole thing with just one line of PowerShell!