Community blog for Scottish VMUG members

Terraform

It’s now 6 weeks into the year and i figure it’s finally time to do something that i’ve been meaning to do since late last year… And that’s to to publish my personal objectives for 2018. For me it should be two fold it means they’re publicly out there so i can judge (and be judged) how the year went for me. Secondly i’m sure a lot of my objectives cross over with others in this community so i’m hoping it may spark some conversations and debates as the year goes on.

Certifications:

VCAP-DCV – So as posted last year (actually oops, that’s still in draft!) well spoiler alert on the 2nd attempt i got my VCAP-DCD, so it’s high on my list to aim for the 2nd VCAP which would of course unlock VCIX for me. This has to be my #1 goal for the year

About a year ago, like so many others i decided to embark on some AWS certs. I started working through the training but then it totally stalled. As i had an expiring exam voucher i forced issue and its scheduled for 3 months time. I need to set aside sufficient time between now and then to give myself any chance. I’m going for AWS Certified Solutions Architect – Associate

New Technologies:

Ansible and SaltStack . The scale of things at my new job compared to my old one is staggering. Everything is multiplied by 10x. Therefore it’s going to be essential for me to get much more familiar with configuration management

This has been cross posted from my own blog vGemba.net. Go check it out!

Wrap up

We have barely scratched the surface with Terraform. It is a very powerful piece of software that can do much more than building a single VM from a template. I do find the documentation around the vSphere provider to be lacking and there is not much out there on the internet on using it with vSphere, so it’s been a lot of experimentation for me but very enjoyable.

I first started playing with Terraform after watching Nick Colyer’s excellent Pluralsight course Automating AWS and vSphere with Terraform. It gives good demo driven examples similar to what I have shown in this series but goes further by delving into Modules, local provisoners, remote provisioners, etc. If you have Pluralsight access go check it out.

I also found this series of posts from Gruntwork to be excellent. The posts have actually been converted into a book called Terraform: Up & Running so you should go check it out.

This has been cross posted from my own blog vGemba.net. Go check it out!

Introduction

In Part 1 and Part 2 we downloaded, setup, and then created a simple VM using Terraform. Let’s look how to use variables and the files required for this.

Existing Code

Let’s look at the code from Part 2:

provider"vsphere"{user="username@corp.contoso.com"# You need to use this format, not example\usernamepassword="Password1"vsphere_server="vcenter.corp.contoso.com"# If you use self-signed certificatesallow_unverified_ssl=true}resource"vsphere_virtual_machine""webserver"{name="webserver1"vcpu=1memory=2048network_interface{label="VM Network"}disk{datastore="datastore"template="MicroCore-Linux"}}

This has been cross posted from my own blog vGemba.net. Go check it out!

Introduction

In Part 1 of this series we went about installing Terraform, verifying it was working and setting up Visual Studio Code. In this part we will cover some Terraform basics.

Terraform Components

The three Terraform Constructs we are going to look at are:

Providers

Resources

Provisioners

Providers

Providers are the resources or infrastructure we can interact with in Terraform. These can include AWS, Azure, vSphere, DNS, etc. A full list is available on the Terraform website. As you can see it’s a very big list. In this series we will concentrate on the VMware vSphere Provider.

Resources

Resources are the things we are going to use in the provider. In the vSphere realm this can be a Virtual Machine, Networking, Storage, etc.

Provisioners

Terraform uses Provisioners to talk to the back end infrastructure or services like vSphere to create your Resources. They essentially are used to execute scripts to create or destroy resources.

Setup Terraform for vSphere

Open up Visual Studio Code and create a new file called main.tfin the folder C:\Terraform. If you have added C:\Terraform to your Path environment variable save main.tf anywhere you like, but of course the best place for all of your Terrform files is source control…

Introduction

Infrastructure as code (IaC) is the process of managing and provisioning computer data centers through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools.

In the case of Terraform this means using code to *declare* what we want from vSphere, AWS, Azure, OpenStack etc. and then Terraform goes and creates the infrastructure to our declared final state. This is the opposite to Procedural Infrastructure where we have to describe *how* to get our end result. Terraform does the hard work in figuring out how to create the infrastructure we have defined – we don’t have to worry how to actually create it or the sequence of steps to get there.