Exercise - Prepare virtual networks for peering by using Azure CLI commands
Let's say your company is now ready to implement virtual network peering. You want to connect systems that are deployed in different virtual networks. To test this plan, you start by creating virtual networks to support the services your company is already running in Azure. You need three virtual networks:
- The Sales virtual network is deployed in North Europe. Sales systems use this virtual network to process the data added after a customer is engaged. The Sales team wants access to Marketing data.
 - The Marketing virtual network is deployed in North Europe. Marketing systems use this virtual network. Members of the Marketing team regularly chat with the Sales team. To share their data with the Sales team, they must download it because the Sales and Marketing systems aren't connected.
 - The Research virtual network is deployed in West Europe. Research systems use this virtual network. Members of the Research team have a logical working relationship with Marketing, but they don't want the Sales team to have direct access to their data.
 
You're going to create the following resources:
| Virtual network | Region | Virtual network address space | Subnet | Subnet address space | 
|---|---|---|---|---|
| SalesVNet | North Europe | 10.1.0.0/16 | Apps | 10.1.1.0/24 | 
| MarketingVNet | North Europe | 10.2.0.0/16 | Apps | 10.2.1.0/24 | 
| ResearchVNet | West Europe | 10.3.0.0/16 | Data | 10.3.1.0/24 | 
Note
This exercise is optional. If you want to complete this exercise, you'll need to create an Azure subscription before you begin. If you don't have an Azure account or you don't want to create one at this time, you can read through the instructions so you understand the information that's being presented.
Note
You need to use a resource group to complete the steps in this exercise. You can use a resource group that you already created, or you can create a new resource group specifically for this exercise. If you choose to create a new resource group, that will make it easier to clean up any resources that you create as you complete the exercise. If you don't have an existing resource group or you want to create a new one specifically for this exercise, you can follow the steps in Use the Azure portal and Azure Resource Manager to manage resource groups to create a resource group by using the Azure portal, or you can follow the steps in Manage Azure resource groups by using Azure CLI to create a resource group by using the the Azure CLI.
Note
Throughout this exercise, replace myResourceGroupName in the examples with the name of an existing resource group, or the name of the resource group that you created for this exercise.
Create the virtual networks
In Cloud Shell, run the following command to create the virtual network and subnet for the Sales systems:
az network vnet create \ --resource-group "myResourceGroupName" \ --name SalesVNet \ --address-prefixes 10.1.0.0/16 \ --subnet-name Apps \ --subnet-prefixes 10.1.1.0/24 \ --location northeuropeRun the following command to create the virtual network and subnet for the Marketing systems:
az network vnet create \ --resource-group "myResourceGroupName" \ --name MarketingVNet \ --address-prefixes 10.2.0.0/16 \ --subnet-name Apps \ --subnet-prefixes 10.2.1.0/24 \ --location northeuropeRun the following command to create the virtual network and subnet for the Research systems:
az network vnet create \ --resource-group "myResourceGroupName" \ --name ResearchVNet \ --address-prefixes 10.3.0.0/16 \ --subnet-name Data \ --subnet-prefixes 10.3.1.0/24 \ --location westeurope
Confirm the virtual network configuration
Let's take a quick look at what you created.
View the virtual networks you've created by running the following command in Cloud Shell:
az network vnet list --query "[?contains(provisioningState, 'Succeeded')]" --output tableYour output should look like this example:
Location Name EnableDdosProtection ProvisioningState ResourceGuid ResourceGroup ----------- ------------- ---------------------- ------------------- ------------------------------------ ------------------------------------------ westeurope ResearchVNet False Succeeded 9fe09fe0-d6cd-4043-aba8-b5e850a91251 learn-cb081b92-bc67-49cf-a965-1aeb40a2e25c northeurope SalesVNet False Succeeded 8f030706-cce4-4a7b-8da2-a9f738887ffd learn-cb081b92-bc67-49cf-a965-1aeb40a2e25c northeurope MarketingVNet False Succeeded ffbf8430-b0eb-4c3d-aa94-3b3156b90bed learn-cb081b92-bc67-49cf-a965-1aeb40a2e25c
Create virtual machines in each virtual network
Now, you deploy some Ubuntu virtual machines (VMs) in each of the virtual networks. These VMs simulate the services in each virtual network. In the final unit of this module, you use these VMs to test connectivity between the virtual networks.
In Cloud Shell, run the following command, replacing
<password>with a password that meets the requirements for Linux VMs, to create an Ubuntu virtual machine (VM) in the Apps subnet of SalesVNet. Note this password for later use.az vm create \ --resource-group "myResourceGroupName" \ --no-wait \ --name SalesVM \ --location northeurope \ --vnet-name SalesVNet \ --subnet Apps \ --image Ubuntu2204 \ --admin-username azureuser \ --admin-password <password>Note
The
--no-waitparameter in this command lets you continue working in Cloud Shell while the VM is building.Run the following command, replacing
<password>with a password that meets the requirements for Linux VMs, to create another Ubuntu VM in the Apps subnet of MarketingVNet. Note this password for later use. The VM might take a minute or two to be created.az vm create \ --resource-group "myResourceGroupName" \ --no-wait \ --name MarketingVM \ --location northeurope \ --vnet-name MarketingVNet \ --subnet Apps \ --image Ubuntu2204 \ --admin-username azureuser \ --admin-password <password>Run the following command, replacing
<password>with a password that meets the requirements for Linux VMs, to create an Ubuntu VM in the Data subnet of ResearchVNet. Note this password for later use.az vm create \ --resource-group "myResourceGroupName" \ --no-wait \ --name ResearchVM \ --location westeurope \ --vnet-name ResearchVNet \ --subnet Data \ --image Ubuntu2204 \ --admin-username azureuser \ --admin-password <password>The VMs might take several minutes to reach a running state.
To confirm that the VMs are running, run the following command. The Linux
watchcommand is configured to refresh every five seconds.watch -d -n 5 "az vm list \ --resource-group "myResourceGroupName" \ --show-details \ --query '[*].{Name:name, ProvisioningState:provisioningState, PowerState:powerState}' \ --output table"A ProvisioningState of Succeeded and a PowerState of VM running indicates a successful deployment for the VM.
When your VMs are running, you're ready to move on. Press
Ctrl-cto stop the command and continue on with the exercise.