You know, back in the Days, when you created your virtual machines all unique and by feet? Create the VM on the Hypervisor, mount Image, install and wait. Sure, this is also something to do when it comes to Cloud IaaS Services, and the period to wait for the completion of the machines has decreased enormous in the cloud. But, what if we don’t speak about one or two machines, what if we talk about an enterprise Scale, a big Testing Environment with many infrastructure resources, also beside the VM itself. What if we speak about Container solutions like Kubernetes, that need to be redeployed quickly and maybe automatically in case of an Error? This is something where clicking through the GUI and create your machines and infrastructure resources around them by hand, will quickly come to it’s limits.
Microsoft recommends to use ARM Templates for scenarios like these. And this is fine and valid, as you can create the infrastructure with the GUI and then get a Exported ARM Template for exactly this infrastructure to redeploy from Powershell. This will increase the ability to recreate broken Services and could be a backup solution for the pure infrastructure, not for the data.
For me, as i had been working for a IT Outsourcing provider, that needs this opportunity not only for Azure, but also maybe for AWS, Google or VMWare. So i came to the point to look out for a solution that fits for all this Providers. I quickly came to Hashicorp, that provides with Terraform a solution that fit’s this demand very good. So you can use various providers to get your things done in many environments. Also the Hashicorp Configuration Language(HCL), used by Terraform, is very user friendly and was easier to adopt for me then the JSON format of the ARM Templates.
So i started with a small Starting Script, only deployed a resource group, a VNET and Subnet and a virtual machine. Didn’t take long till i had it ready and my first small „TF“ File was born. I downloaded the Azure provider from the Terraform Homepage and brought it all together.
The TF File (but only One!) and the Azure Terraform Provider Executable need to be in the same folder. When you now use a elevated Command Line check if your connected to the Tenant with your Account (az account show). Now navigate to the Folder, you will perform the Terraform Command Terraform Init to initialize the Terraform provider and download the needed Stuff from the Internet. The Provider to be used and the target Tenant and Subscription is defined in the TF-File:
When this is done, next step is to do a Terraform plan Command. Now the TF File will be checked for Syntax Errors and reconciled against the defined Subscription. A TFState File will be created with the current State in Azure. When this went fine you will get at the End a Information of what will be added, changed or destroyed. Added Stuff will be highlighted in green, changed Stuff in yellow and destroyed Stuff in red. When this is all fine for you, proceed and do a Terraform apply Command to run this Script. You will be asked again to confirm with yes once the planing run is completed and before any changes will be proceeded. And, this is it! No magic, no rocket science. Sure this is the easiest way to get it done and you can improve the Scripts and so on, but this will come step by step.
I would recommend to have a look on the Terraform possibilities and also at the other Hashicorp Services, as they fit very well in the Microsoft Ecosystem and there is a close partnership between this two Company’s. And as said earlier, when you start to manage Azure IaaS in a bigger Scale, you will somewhat come to the point where you need to use Code for deployments, also in automated deployment pipelines. To dive deeper in the Terraform Topic, you should have a look to the new released Edition of Terraform: Up & Running by Yevgeniy Brikman.
So, have fun with testing and feel free to get in touch with me.