Terraform

An open source tool from HashiCorp.

Terraform enables you to safely and predictably create, change, and improve production infrastructure. It is an open source tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned. -terraform.io

TL;DR;

Terraform is used to create a cloud infrastructure defined in code. This means that you have a consistent and repeatable way of deploying infrastructure, containers and applications. The benefits are many, e.g. the servers are implicitly immutable, so instead of patching and updating running servers, you redeploy your app with a new and updated image. In addition you can integrate your deployment with code reviews and approvals, before a new deployment is triggered.

Install

Download Terraform here

  • Copy files from the zip to c:\terraform or any other folder of choice
  • Add the terraform binaries in your path by running: set PATH=%PATH%;C:\terraform (of course use the folder you chose above...)

Minimum viable Terraform

Script targeting the Azure provider

# set up the Azure provider
provider "azurerm" {
  subscription_id = "your_subscription_id_from_script_execution"
  client_id       = "your_client_id_from_script_execution"
  client_secret   = "your_client_secret_from_script_execution"
  tenant_id       = "your_tenant_id_from_script_execution"
}

# create a resource group 
resource "azurerm_resource_group" "helloterraform" {
    name = "terraformtest"
    location = "West US"
}

Executing the script

Simply type this in the folder where you have saved the above script with an .tf file ending:

terraform plan

terraform apply