The IaaS capabilities of Azure could be very handy when you need to create temporary development/test environments during the SDLC. Automating the creation and clean-up of these environments could save a lot of time and compute time ($$).
Azure exposes an interface based on PowerShell to automate all the steps required to do this, and I spent some time researching how to properly do it. You will find many references and blog post on how to create VMs using the PowerShell API in Azure; however I did not find many updated, accurate references of how to do it for an entire environment. Probably because the API has evolved so quickly and these articles are no longer relevant.. The results are summarized in the following script which demonstrates the creation of a standard deployment of an enterprise multi-tier environment (web front-end, application server and database server).
This sample script will create 3 VMs running “Windows Server 2008 R2 SP1”: WFE, App Server and DB Server. All VMs will be “grouped” in the same Azure Cloud Service: $CloudServiceName.
If you plan to use it, make sure you edit the environment variables in the top of the script:
- The Environment Name: $EnvironmentName
- The storage account used to store the VHDs: $StorageAccount
- Location of the Azure Publishing settings file: $AzurePubSettingsFile
- Size of the VMs: $VMSize
- Location – use get-azurelocation for a list of locations: : $Location
- Admin Username and Password – this is the local account you will use to remote into them: $AdminUserName and $AdminPwd
- OS: $OSFamily
To shut down and clean-up the VMs created, you could use the following script:
Some aspects were not fully covered in this version of the script:
· Networking: VMs will be able to talk between each other, but we currently do not have any control on the addressing assigned to them.
· AD: VMs are created as standalone servers, not part of an AD domain.
I hope you can find this helpful and time saving.