What the H*ck is Terraform: An Introduction

I have been absent from sharing my learnings for quite some time. My first article of 2025 is also my first after a four month writing hiatus. Isn’t it a nice coincidence that my first article of the new year is on a new technology (new in the sense that I haven’t done much with it before) that I am currently diving deep into? If you are new to Terraform as well, don’t worry because I got you. The aim of this article is to give you a soft-landing introduction to Terraform. Let’s glide into it! Terraform is an open-source, cloud-agnostic (meaning you can use Terraform to provision and manage infrastructure on different cloud platforms) infrastructure as code tool that enables you to safely and predictably provision and manage infrastructure in the cloud. If you’ve ever had to do a task such as creating a couple of Amazon EC2 instances with security groups and other configurations by having to click around in the AWS management console, you can attest to how tedious that might have been. Terraform makes carrying out such tasks a breeze. Before we go any further, here are some of the benefits of using Terraform to keep you interested and inspire you to consider using it the next time you are building out infrastructure in the cloud. These benefits include: Terraform templates can be source controlled that is you can use GitHub, BitBucket and related technologies to keep track of the different versions of your Terraform templates. It offers multi-cloud support (cloud-agnostic) with over 100 providers including Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP) Has separate plan and apply stages so you can verify changes to your infrastructure before they happen (more on this later). Offers a public registry of modules that make provisioning common groups of resources easy. It is stateful and keeps track of all infrastructure it provisions. Now it’s time to dive deeper. In this section of the article, we will explore Terraform’s CLI tool, Terraform Configuration, the HashiCorp Configuration Language (HCL) and Terraform providers. Terraform CLI Tool Terraform is written in GoLang and packaged as a single binary which makes installing it a breeze. You can download the binaries for the open-source version of Terraform by clicking here. Make sure you are downloading the binary that matches the OS of the computer you want to install Terraform on. Once Terraform is installed, it comes with a list of commands and subcommands you can use to provision and make changes to your infrastructure. The CLI has three main commands: terraform init terraform plan terraform apply Time to look at each one in detail. terraform init: This command initializes a working directory containing Terraform configuration files. This is the first command that you should run after writing a new Terraform configuration or cloning an existing one from version control. Running this command multiple times does not negatively affect your project as it skips the re-initializing process unless in scenarios where changes have been made to your configuration. terraform plan: The command lets you preview the changes Terraform is going to make to your infrastructure when you run terraform apply. It essentially shows you a detailed execution plan of the resources that will created, modified or destroyed. This helps you verify that the proposed changes tie with what you expect to happen when you apply the changes. There is no need to run this command when you are sure that what you have written in your configuration file will run exactly as expected. terraform apply: As the name suggests, this is the command you run when you want to apply the changes made to your configuration files. It is the command that actually creates or modifies your infrastructure. When you run the command without the optional -auto-approve flag, it requires that you manually confirm that you want to have the proposed changes applied by typing yes in the interactive terminal.

Jan 17, 2025 - 18:52
What the H*ck is Terraform: An Introduction

I have been absent from sharing my learnings for quite some time. My first article of 2025 is also my first after a four month writing hiatus. Isn’t it a nice coincidence that my first article of the new year is on a new technology (new in the sense that I haven’t done much with it before) that I am currently diving deep into? If you are new to Terraform as well, don’t worry because I got you. The aim of this article is to give you a soft-landing introduction to Terraform. Let’s glide into it!

Terraform is an open-source, cloud-agnostic (meaning you can use Terraform to provision and manage infrastructure on different cloud platforms) infrastructure as code tool that enables you to safely and predictably provision and manage infrastructure in the cloud.

If you’ve ever had to do a task such as creating a couple of Amazon EC2 instances with security groups and other configurations by having to click around in the AWS management console, you can attest to how tedious that might have been. Terraform makes carrying out such tasks a breeze. Before we go any further, here are some of the benefits of using Terraform to keep you interested and inspire you to consider using it the next time you are building out infrastructure in the cloud. These benefits include:

  • Terraform templates can be source controlled that is you can use GitHub, BitBucket and related technologies to keep track of the different versions of your Terraform templates.

  • It offers multi-cloud support (cloud-agnostic) with over 100 providers including Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP)

  • Has separate plan and apply stages so you can verify changes to your infrastructure before they happen (more on this later).

  • Offers a public registry of modules that make provisioning common groups of resources easy.

  • It is stateful and keeps track of all infrastructure it provisions.

Now it’s time to dive deeper. In this section of the article, we will explore Terraform’s CLI tool, Terraform Configuration, the HashiCorp Configuration Language (HCL) and Terraform providers.

Terraform CLI Tool

Terraform is written in GoLang and packaged as a single binary which makes installing it a breeze. You can download the binaries for the open-source version of Terraform by clicking here. Make sure you are downloading the binary that matches the OS of the computer you want to install Terraform on.

Once Terraform is installed, it comes with a list of commands and subcommands you can use to provision and make changes to your infrastructure. The CLI has three main commands:

  • terraform init

  • terraform plan

  • terraform apply

Time to look at each one in detail.

terraform init: This command initializes a working directory containing Terraform configuration files. This is the first command that you should run after writing a new Terraform configuration or cloning an existing one from version control. Running this command multiple times does not negatively affect your project as it skips the re-initializing process unless in scenarios where changes have been made to your configuration.

terraform plan: The command lets you preview the changes Terraform is going to make to your infrastructure when you run terraform apply. It essentially shows you a detailed execution plan of the resources that will created, modified or destroyed. This helps you verify that the proposed changes tie with what you expect to happen when you apply the changes. There is no need to run this command when you are sure that what you have written in your configuration file will run exactly as expected.

terraform apply: As the name suggests, this is the command you run when you want to apply the changes made to your configuration files. It is the command that actually creates or modifies your infrastructure. When you run the command without the optional -auto-approve flag, it requires that you manually confirm that you want to have the proposed changes applied by typing yes in the interactive terminal.