Terraform Azure Provider – Deploy a Virtual Machine and Join Domain

I’ve spent quite a lot of time working with Terraform over the past few months both at work and at home, so far I’ve been concentrating on the vSphere provider, I thought it was time to take a look at the Azure provider.  The beauty of Terraform is that it’s vendor agnostic, so once you understand how the logic works, in theory it should be a relatively painless transition to working with a different provider.   I’ve been using Azure for the past year or so, mostly for personal projects and for experimentation, during my study for the Azure Certified Administrator I worked with Arm templates and found them to be quite cumbersome,  they require an awful lot of code just to deploy a simple virtual machine.  Take a look here for an example of an Arm template to deploy a VM, then compare it to my completed test project on GitHub.

My project goes a step further also joins the machine to the domain, it will deploy the following…

  • Create Resource Group
  • Create VNET
  • Create Subnet
  • Create Public IP Address
  • Create Network Security Group and open RDP firewall port
  • Create NIC
  • Create Virtual Machine
  • Join virtual machine to custom domain (optional)

 

If you want to quickly deploy some infrastructure to Azure.

  • Create a clone of my repository to your local workstation.
  • Run ‘terraform init’ to download the Azure provider plugin
  • Edit main.tf with your subscription ID

  • run ‘terraform plan’
  • run ‘terraform apply’ once you are happy with the plan

This was my first attempt at deploying infrastructure into Azure using Terraform, I had everything up and running in a couple of hours, I accept it’s not the most complex deployment, but it was a useful starting point and one from which I intend to expand upon in the very near future.

My next challenge is to deploy some infrastructure in AWS using Terraform, hopefully a blog post will follow soon.

I’m still working away on #100DaysofCode(Python), I do need to check how many days I’ve got left as I’ve lost track! I must be fast approaching 100 days.  I’ll put up another post once I’ve caught up with things, thanks for reading!

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s