Provisioning a Virtual Machine on Azure
This post will help you setup a CentOS 7.1 Virtual Machine on Azure using Azure Resource Manager (ARM) and PowerShell.
1) Finding a CentOS VM Image
Using our favorite PowerShell tools, we can discover details about pre-built CentOS 7.1 Azure Virtual Images.
Switch-AzureMode -Name AzureResourceManager $location = 'eastus' Get-AzureVMImagePublisher -Location $location $publisherName = 'OpenLogic' Get-AzureVMImageOffer -Location $location ` -PublisherName $publisherName $offer = 'CentOS' Get-AzureVMImageSku -Location $location ` -PublisherName $publisherName ` -Offer $offer ` | Select-Object -Property 'Skus' $sku = '7.1' Get-AzureVMImage -Location $location ` -PublisherName $publisherName ` -Offer $offer ` -Skus $sku $verison = '7.1.20150731' Get-AzureVMImage -Location $location ` -PublisherName $publisherName ` -Offer $offer ` -Skus $sku ` -Version $verison
2) Creating The ARM Template
We can use the CentOS Virtual Image information to create a CentOS 7.1 Standard_A1 Virtual Machine Template. Name this file DeploymentTemplate.json.
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "newStorageAccountName": { "type": "string", "metadata": { "description": "Unique DNS Name for the Storage Account where the Virtual Machine's disks will be placed." } }, "adminUsername": { "type": "string", "metadata": { "description": "User name for the Virtual Machine." } }, "adminPassword": { "type": "securestring", "metadata": { "description": "Password for the Virtual Machine." } }, "dnsNameForPublicIP": { "type": "string", "metadata": { "description": "Unique DNS Name for the Public IP used to access the Virtual Machine." } }, "OSVersion": { "type": "string", "defaultValue": "7.1", "allowedValues": [ "7.1" ] } }, "variables": { "addressPrefix": "10.0.0.0/16", "dataDiskSize": "100", "imageOffer": "CentOS", "imagePublisher": "OpenLogic", "location": "East US", "nicName": "myVMNic", "OSDiskName": "osdisk", "publicIPAddressType": "Dynamic", "storageAccountType": "Standard_LRS", "subnetName": "Subnet", "subnetPrefix": "10.0.0.0/24", "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]", "virtualNetworkName": "MyVNET", "vmName": "msbriseboislinux", "vmSize": "Standard_A1", "vmStorageAccountContainerName": "vhds", "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]" }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "name": "[parameters('newStorageAccountName')]", "apiVersion": "2015-05-01-preview", "location": "[variables('location')]", "tags": { "displayName": "StorageAccount" }, "properties": { "accountType": "[variables('storageAccountType')]" } }, { "apiVersion": "2015-05-01-preview", "type": "Microsoft.Network/publicIPAddresses", "name": "[parameters('dnsNameForPublicIP')]", "location": "[variables('location')]", "tags": { "displayName": "PublicIPAddress" }, "properties": { "publicIPAllocationMethod": "[variables('publicIPAddressType')]", "dnsSettings": { "domainNameLabel": "[parameters('dnsNameForPublicIP')]" } } }, { "apiVersion": "2015-05-01-preview", "type": "Microsoft.Network/virtualNetworks", "name": "[variables('virtualNetworkName')]", "location": "[variables('location')]", "tags": { "displayName": "VirtualNetwork" }, "properties": { "addressSpace": { "addressPrefixes": [ "[variables('addressPrefix')]" ] }, "subnets": [ { "name": "[variables('subnetName')]", "properties": { "addressPrefix": "[variables('subnetPrefix')]" } } ] } }, { "apiVersion": "2015-05-01-preview", "type": "Microsoft.Network/networkInterfaces", "name": "[variables('nicName')]", "location": "[variables('location')]", "tags": { "displayName": "NetworkInterface" }, "dependsOn": [ "[concat('Microsoft.Network/publicIPAddresses/', parameters('dnsNameForPublicIP'))]", "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" ], "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "privateIPAllocationMethod": "Dynamic", "publicIPAddress": { "id": "[resourceId('Microsoft.Network/publicIPAddresses',parameters('dnsNameForPublicIP'))]" }, "subnet": { "id": "[variables('subnetRef')]" } } } ] } }, { "apiVersion": "2015-05-01-preview", "type": "Microsoft.Compute/virtualMachines", "name": "[variables('vmName')]", "location": "[variables('location')]", "tags": { "displayName": "VirtualMachine" }, "dependsOn": [ "[concat('Microsoft.Storage/storageAccounts/', parameters('newStorageAccountName'))]", "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" ], "properties": { "hardwareProfile": { "vmSize": "[variables('vmSize')]" }, "osProfile": { "computername": "[variables('vmName')]", "adminUsername": "[parameters('adminUsername')]", "adminPassword": "[parameters('adminPassword')]" }, "storageProfile": { "imageReference": { "publisher": "[variables('imagePublisher')]", "offer": "[variables('imageOffer')]", "sku": "[parameters('OSVersion')]", "version": "latest" }, "osDisk": { "name": "osdisk", "vhd": { "uri": "[concat('http://',parameters('newStorageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]" }, "caching": "ReadWrite", "createOption": "FromImage" } }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]" } ] } } } ] }
3) Provisioning a CentOS Virtual Machine
Prepare the Template Parameter File with the template’s parameter values. Name this file DeploymentTemplate.param.dev.json.
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "newStorageAccountName": { "value": "mslinuxbrisebois" }, "adminUsername": { "value": "brisebois" }, "dnsNameForPublicIP": { "value": "briseboisdns" } } }
Then deploy the Azure Resource Manager Template and Parameters using PowerShell.
New-AzureResourceGroup -Name 'mslinuxbrisebois' ` -Location 'eastus' ` -TemplateFile 'DeploymentTemplate.json' ` -TemplateParameterFile 'DeploymentTemplate.param.dev.json' ` -Force -Verbose # New-AzureResourceGroup VERBOSE Log VERBOSE: 11:16:53 AM - Created resource group 'mslinuxbrisebois' in location 'eastus' VERBOSE: 11:16:53 AM - Template is valid. VERBOSE: 11:16:54 AM - Create template deployment 'DeploymentTemplate'. VERBOSE: 11:16:59 AM - Resource Microsoft.Storage/storageAccounts 'mslinuxbrisebois' provisioning status is running VERBOSE: 11:16:59 AM - Resource Microsoft.Network/publicIPAddresses 'briseboisdns' provisioning status is running VERBOSE: 11:16:59 AM - Resource Microsoft.Network/virtualNetworks 'MyVNET' provisioning status is running VERBOSE: 11:17:10 AM - Resource Microsoft.Network/publicIPAddresses 'briseboisdns' provisioning status is succeeded VERBOSE: 11:17:10 AM - Resource Microsoft.Network/virtualNetworks 'MyVNET' provisioning status is succeeded VERBOSE: 11:17:12 AM - Resource Microsoft.Network/networkInterfaces 'myVMNic' provisioning status is succeeded VERBOSE: 11:17:26 AM - Resource Microsoft.Storage/storageAccounts 'mslinuxbrisebois' provisioning status is succeeded VERBOSE: 11:17:28 AM - Resource Microsoft.Compute/virtualMachines 'msbriseboislinux' provisioning status is running VERBOSE: 11:19:29 AM - Resource Microsoft.Compute/virtualMachines 'msbriseboislinux' provisioning status is succeeded ResourceGroupName : mslinuxbrisebois Location : eastus ProvisioningState : Succeeded Tags : Permissions : Actions NotActions ======= ========== * Resources : Name Type Location ================ =================================== ======== msbriseboislinux Microsoft.Compute/virtualMachines eastus myVMNic Microsoft.Network/networkInterfaces eastus briseboisdns Microsoft.Network/publicIPAddresses eastus MyVNET Microsoft.Network/virtualNetworks eastus mslinuxbrisebois Microsoft.Storage/storageAccounts eastus ResourceId : /subscriptions/c14fc8bb-3180-4844-965b-7cd9d90cf7cd/resourceGroups/mslinuxbrisebois