Azure Cross-Platform Automation
Step-by-Step: Create a Virtual Machine with Azure xPlat CLI
During this demonstration, we'll use the Microsoft Azure Cross-Platform (xPlat) CLI Tool to create a Microsoft Azure Virtual Network, with a single Subnet. This Virtual Network and Subnet will be used to deploy the Network Interface into. The Network Interface will be attached to the Azure Virtual Machine, giving it access to the Virtual Network.
Hello. In this demonstration, we're going to create a virtual network using the Azure cross-platform CLI tool using imperative provisioning, which basically means that we're going to provision resources one by one.
The first thing I'm going to do is create a resource group for us. So we're going to call the Azure group create command, then we're going to specify a name for the group. So we'll call this Cloud Academy Vnet. And then we're going to specify the location. Now, if you don't know a list of locations that are available, we can use the Azure location command. And as you can see, we've got a sub-command called list. So if we just call Azure location list, you'll see all of the Azure locations, or regions, where we can deploy resources into. So I used the west US region to create the resource group.
So now we're going to call the Azure command again, and as you can see, we've got a sub-command called network. So let's call Azure network and see what sub-commands are available. As you can see, there is a series of commands that allow us to manage things such as VPN connections, express route, route tables, and much more. So let's go ahead and scroll on up to the basic Azure networking commands.
So we want Azure network vnet. So the vnet sub-command allows us to create a new virtual network. So we're going to call Azure network vnet create, and that will create us a virtual network. So let's call Azure network vnet create --help. Now, as you can see, there's a series of input parameters that allow us to create a virtual network. So we're going to specify the resource group, which is what we just created a few minutes ago. Then we're going to specify a name for the virtual network, the Azure location or region that we want to deploy it in, and then we also need to specify the address space for the virtual network, and any DNS servers that we want to point our virtual machines to once they're deployed into that virtual network. We can also optionally specify tags. So I'm going to call Azure network vnet create, and then start adding these parameters.
So the resource group is going to be Cloud Academy vnet. That's the one we just created. Then the name of the virtual network will be CA Vnet. The location, we'll use west US. And then the address prefixes, we'll use 10.10.0.0/16. And then the DNS servers, we'll use 126.96.36.199. So let's go ahead and just run that command, and as you can see, it's going to go out and create that virtual network called CA Vnet.
Now, before we can actually deploy Azure virtual machines into the virtual network, we first have to create a subnet. So we've already specified the IP address space for the virtual network, but we have to create subnets out of that in order to provision virtual machines into. So let's go ahead and call Azure network, and go find the commands to create a subnet. So the subnet command is going to be network vnet subnet create. So let's call Azure network vnet subnet create, and then tack on the --help parameter. So again, we're going to specify the resource group name, the vnet inside the resource group. We'll specify a name for the new subnet and the address prefix.
Now, there's some other parameters here that allow us to do things like associate a network security group or a routing table with the subnet, but those are entirely optional, so we won't do that for the time being. So let's call Azure network vnet subnet create, and then specify the resource group, which is Cloud Academy vnet, the vnet name, which is CA Vnet, and then we'll specify a name for the subnet, so we'll call it CA Subnet. And then we need to specify an address prefix for the subnet that is a subset of the IP address base that we specified for the virtual network. So the virtual network was 10.10/16, so let's go ahead and use 10.10.5.0/24 for our subnet.
So as you can see, the Azure Xplat CLI tool is going out and creating us a subnet called CA Subnet. So now that we've created the virtual network and the subnet, the next steps we'll have are to create the network interface, and then for the VM, we'll create a storage account, and then we'll be able to create the virtual machine itself and deploy it into the subnet.
Trevor Sullivan is a Microsoft MVP for Windows PowerShell, and enjoys working with cloud and automation technologies. As a strong, vocal veteran of the Microsoft-centric IT field since 2004, Trevor has developed open source projects, provided significant amounts of product feedback, authored a large variety of training resources, and presented at IT functions including worldwide user groups and conferences.