My new job has been full of cloud things and working with other teams to find good ways to automate some of the things we do has been on my radar for some time. There has been some PowerShell and some Bash scripting with scheduled runs across different cloud providers - trying to find a way to execute things that is sustainable, repeatable, and easy enough to ensure it will be used widely in the future.

A conversation this week about what we are currently doing in Google Cloud and how we plan to keep things moving forward brought up Terraform from HashiCorp. I have used Desired State Configuration in the past and tinkered in a very limited sense with Chef and Puppet, but I had not used this tool. In a bit of reading to see what it was all about, I have come up with this summary - at a basic level, terraform is a cloud agnostic Infrastructure building engine that will make creating resources very repeatable. Combine this with the management capabilities of Chef, Puppet, and/or DSC and who knows what might happen? World domination? Maybe, but more likely a computing strategy that can shift between the major cloud providers on short notice and allow a company to be all over the place... just like that.

We are not there yet - far from it, but I have been tinkering around a bit in Terraform this week to see how much work it might be to create a resource. In the Google Cloud trial account I have, I was able to build a generic VM in about a minute and a half and tear it down in about the same timeframe. Mind you, I spent a good two hours tinkering with VScode to help make the next .tf file easier to build... I will publish the snippet file for VSCode to GitHub at some point, not sure it has all the placeholders I want just yet, but it will soon.

Once I was happy enough with it, I used this following to build a vm:

provider "google" {
    #credentials = "$file("account.json")}"
    project = "ds-terraform-testing"
    region = "${var.region}"
}

resource "google_compute_instance" "my-test-host" {
name     = "my-first-terraform-compute-instance"
machine_type = "n1-standard-1"
zone = "us-central1-a"
tags = ["test","terraform"]

boot_disk {
    initialize_params {
        image = "rhel-cloud/rhel-7"
    }
}

network_interface {
    network = "default"
    }

}

Nothing fancy at all - just something to see what happens when a terraform config gets applied.

with the file saved I ran terraform plan to see the execution plan - what this would do... and with no errors or red ink on the screen, I was off to the next step - BUILD!

terraform apply

once that got going I opened the compute engine page of the new project in GCP and refreshed all of twice - and bingo, the new vm with nothing more than an OS was running and waiting for something to do.

Since I was simply looking to see how long this might take I knocked the instance down after about ten minutes with terraform destroy.

Sure - this is not some huge infrastructure that will run all the things, but it is a start - a fairly fast start. I think I am going to like this stuff quite a lot... sure it isnt PowerShell, but that doesn't mean it can't be mixed and matched with other tools to ensure some integration and extremely scriptable buildouts.

After a first try with Terraform, I am quite impressed with what this is capable of doing for me. Lots to learn, but that is half the fun... just remember to power off the cloud toys when they aren't in use.

You can get Terraform from terraform.io or if you are into Chocolatey - it is in the public gallery there too - choco install terraform -y (in an elevated PowerShell session) will get you started - all at no cost - the tools are open source and freely available. Remember though - the cloud will cost you money if you leave things running!! Do not turn off production, but make sure your labs get shutdown ;)

Have fun, try this stuff out, and build some awesome Infrastructure as Code.