Devops - Terraform

Terraform is a tool to provision cloud resources. It is what is known as Infrastructure As Code, meaning that whatever is written is completely reproducible. As opposed to manually configuring web resources through some sort of web ui. This means that web servers, k8s clusters, etc can all be spun through a simple request after writing the necessary configuration files. Relationships between different resources can also be specified.

Terraform is written in a special programming language designed for specifying infrastructure. This language is known as Hashicorp Configuration Language (HCL).

Config files can also be specified such that when create a VPS instance it can be preinstalled with certain software, have arbitrary commands run or more.

Personal Note on Vultr

I use Vultr and there is a guide to do provisioning here

Using this provider requires an api key which can be specified inside the terraform files or in an environment variable VULTRAPIKEY.

Available plans, regions and os’s can be fetched with this command:

# per_page option is to fix annoying pagination
curl "https://api.vultr.com/v2/plans?per_page=500" -X GET
curl "https://api.vultr.com/v2/regions" -X GET
curl "https://api.vultr.com/v2/os" -X GET

A json object is returned listing the available options for each field.

Annoyingly, the cheapest servers do not seem to be an option through this API. I use a simple 512MB RAM cloud compute instance which cannot be chosen.

Terminology

Resources

Are an entity of a cloud service such as a VPS, K8s cluster, etc.

Modules

Are like libraries in other programming languages that allow common code to be abstracted away.