Monthly Archives: October 2019

Terraform vSphere Provider – Deploy multiple virtual machines of varied specifications – Part 1

I recently had the opportunity to work with Terraform which is HashiCorp’s Infrastructure as Code (IaC) offering, it’s an interesting tool as it’s vendor agnostic and can be used with AWS, VMware, Azure and many more software vendors.  Organisations seem to be heading towards a mix of multi-cloud and on-premise Infrastructure which means more tools and more skills to learn for the people supporting it, Terraform seems like it could be a really good choice to help cut down on complexity and staff training/re-training.

The organisation I’m currently working for tasked me with developing a proof of concept so they can determine if the tool is a good fit for their business, they are primarily a VMware house with an increasing footprint in Microsoft Azure.  Terraform has the concept of  ‘Providers’, which basically contain the underlying code that performs all the heavy lifting and interaction with the vendor’s software, for example for VMware there is a vSphere provider, for Amazon Web Services there’s the AWS provider, for the purpose of this post I will be using the vSphere provider.


  • Deploy multiple virtual machines of varying RAM, CPU and Disk Sizes.
  • Create 2 Virtual Machine Folders.
  • Create a Virtual Distributed Switch.
  • Attach the new virtual machines to the new VDS.
  • Place the new Virtual Machines in the correct folder
  • Standardise the code on GitHub so it can be cloned and used on cross region.

Getting Started:

I’m going to assume that you already understand how get Terraform up and running on your workstation.  Once you’ve created a  folder and downloaded the relevant Terraform binaries we can start organising the folder structure.  I want to make sure that other admins can clone the git repo and modify the variables that are relevant to the site they are deploying, I would like to keep the editing of files to a minimum for other admins.

I prefer the structure below as it means that when somebody else  wants to re-use your code they only need to edit the terraform.tfvars file.

  • – This is where you define the provider and describe what you intend to deploy.
  • – For every variable in there needs to be a corresponding variable in
  • terraform.tfvars – This is the only file that needs to be edited once your code has been finalised.



I’ve decided to include a few steps on GitHub set up.

You can set up and account for free on GitHub, once you’re signed in create a new repo, to clone the repo you will need to install git tools to run the git commands, I’m on a Windows machine so I’ve used ‘Git for Windows’.

  • Clone the repo to your workstation

  • Initilaise the repo

Now that the repo is initialised you can create a new branch and start pushing changes to the main repo, below is a quick summary of commands to create a new branch.

  • git add .
  • git commit -m “Initial Commit”
  • git branch Initial_Branch
  • git push origin Initial_Branch

In part 2 of this series we’ll start editing the files…..