Over a million developers have joined DZone.

Automating Windows Azure IaaS Deployment with Powershell

DZone's Guide to

Automating Windows Azure IaaS Deployment with Powershell

· Cloud Zone
Free Resource

Linkerd, the open source service mesh for cloud native applications. Get the complete guide to using Linkerd and Kubernetes to build scalable, resilient applications.

With Windows Azure PowerShell Cmdlets, the process to customize and automate an infrastructure deployment to Windows Azure Infrastructure Services (IaaS) becomes a relatively simple and manageable task. This article examines a sample script which automatically deploys seven specified VMs into three target subnets based on a network configuration file with two availability sets and a load-balancer. The entire deployment took a little more than half an hour.


The developer PowerShell script assumes Windows Azure PowerShell Cmdlets environment has been configured with an intended Windows Azure subscription. A network configuration file is in a specified location.

Network Configuration (netcfg) File

This file can be created from scratch or exported from Windows Azure NETOWRK workspace by first creating a virtual network. Notice in the netcfg file an affinity group and a DNS server are specified.


Overall Program Structure

The four functions represent the key steps in performing a deployment including building a virtual network, deploying VMs, and configuring availability sets and load-balancers, as applicable.


Initialization, Windows Azure Virtual Network and Settings

Within the script, session variables and constants are assigned. The network information needs to be identical with what is defined in netcfg file since they are not automatically populated from an external source at this time.



To deploy multiple VMs programmatically, there is much information repeated. And in some parameters are defined with default values from session variables or the initialization section. When calling a routine, a default value can be overridden by an assigned/passed value.


Since other than the first VM, deploying additional VMs into an existing service does not need to specify the virtual network name. I however employ the same routing with VNetName specified for deploying the first and subsequent VMs into a service, it produces a warning for each VM after the first VM deployed into a service as shown in the user experience later.


Simply passing in an array to the routines and an availability set or a load-balancer will automatically built. These two functions streamline the processes.



Main Program

Rather than creating a cloud service while deploying a VM, I decided to create individual cloud services first. This makes troubleshooting easier since it is very clear when services are created.


Deploy Backend Infrastructure Servers

With a target service in place, I simply loop through and deploy VMs based  on the names specified in an array. So to deploy or place VMs into an availability set or a load-balancer becomes simply by adding machine names into a target array.


Deploy Mid-Tier Workloads


Deploy Frontend Servers

Here, three frontend servers are load-balanced and configured into an availability set.


User Experience

I kicked off at 3:03 PM and it finished at 3:36 PM. The four warnings were due to deploying additional VMs (specifically dc2, sp2013, fe2, and fe3) into their target services while in the function, DeployVMsToAService, I have VNetName specified.


Verified with Windows Azure Portal

Seven VMs were deployed with specified names.


dc1 and dc2 were placed in the availability set, dcAvSet.


fe1, fe2, and fe3 are placed in the availability set, feAvSet.


The three were load-balanced at feEndpoint as specified in the script.


All VMs were deployed into target subnet as shown in the virtual network, foonet.


Session Log and RDP files

The script also produces a log file capturing the states while completing tasks. As a VM is deployed, the associated RDP file is also downloaded into a specified working directory as shown below.


Closing Thoughts

To make the code production ready, more error handling needs to be put in place. A key missing part of the script is the ability to automatically populated the network configuration from or to an external source. Still, the script provides a predictable, consistent, and efficient way to deploy infrastructure with Windows Azure Infrastructure. What must come after is to customize the runtime environment for an intended application, once VMs are in place and followed by installing the application. IaaS outs VMs in place as the foundation for PaaS which provides the runtime for a target application. It is always about the application, never should we forget.

- See more at: http://blogs.technet.com/b/yungchou/archive/2013/05/20/automating-windows-azure-infrastructure-services-iaas-deployment-with-powershell.aspx#sthash.7JxjChsU.dpuf

Linkerd, the open source service mesh for cloud native applications. Get the complete guide to using Linkerd and Kubernetes to build scalable, resilient applications.


Published at DZone with permission of Yung Chou, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}