What is Terraform? A Beginner’s Guide to Infrastructure as Code
A hands-on introduction to Infrastructure as Code with Terraform — learn what it is, why it matters, and how to set it up in minutes.
Terraform Basics: What is Terraform and Why Use It?
If you're new to cloud infrastructure or DevOps, you've probably heard the term Infrastructure as Code (IaC) being tossed around. It sounds fancy, but at its core, it's a simple and powerful idea: managing infrastructure using configuration files instead of manual processes. And Terraform is one of the most popular tools that brings this idea to life.
In this post — the first in our 5-part Terraform Basics series — we’ll walk through what Terraform is, why it’s useful, and how to get started with it.
What is Terraform?
Terraform is an open-source infrastructure as code tool developed by HashiCorp. It lets you define cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share.
Think of Terraform as the automation tool that replaces clicking through a cloud console. Instead of logging into AWS or GCP and creating VMs manually, you describe them in a .tf
file — and Terraform provisions them for you.
Example
Here’s a simple example of what a Terraform config might look like for deploying a virtual machine on Google Cloud:
provider "google" {
project = "my-gcp-project"
region = "us-central1"
}
resource "google_compute_instance" "default" {
name = "my-vm"
machine_type = "e2-medium"
zone = "us-central1-a"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
network = "default"
access_config {}
}
}
With a single command, Terraform will deploy this VM.
Why Use Terraform?
Let’s break it down for beginners: Why should you even bother with Terraform? What makes it different from just using the AWS or Azure console?
1. Consistency and Repeatability
Terraform allows you to define your infrastructure in code, which means:
You can spin up identical environments multiple times (dev, staging, production)
You can version control your infrastructure using Git
You can track changes, roll back, and audit
2. Multi-Cloud Support
Terraform doesn’t just work with one cloud provider — it supports all the major ones (AWS, GCP, Azure, OCI, Alibaba Cloud), and many other providers like GitHub, Datadog, and even Kubernetes.
This makes it a single tool to manage diverse environments.
3. Modular and Scalable
With modules, you can reuse your Terraform code, keep things organized, and scale easily. This is great for teams and projects that grow in complexity over time.
4. Plan Before You Apply
Terraform has a built-in plan
command that shows you exactly what changes it will make before applying them. This gives you safety and visibility.
5. Community and Ecosystem
With a massive open-source community and thousands of available modules in the Terraform Registry, you can build faster and smarter.
Key Concepts in Terraform
Let’s cover a few terms that will come up often in your Terraform journey:
Provider: This defines which cloud platform or service you’re interacting with (e.g.,
google
,aws
).Resource: The basic building block — things like a VM, a firewall rule, a database instance.
Module: A container for multiple resources that can be reused.
State: Terraform keeps track of what it has created using a state file (
terraform.tfstate
).Variables and Outputs: These make your configurations dynamic and reusable.
Terraform Core Workflow (Diagram)
This diagram shows the flow from writing your config files to provisioning resources using terraform init
, plan
, and apply
. It's a simple but powerful visualization of how Terraform operates in practice.
This visualizes the typical Terraform workflow: from writing configs, initializing, planning, applying, and finally provisioning infrastructure.
Installing Terraform
Getting started with Terraform is easy:
On Mac
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
On Linux
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
Verify Installation
terraform version
If you see something like Terraform v1.6.0
, you’re good to go.
Next Steps
Once Terraform is installed, you’ll:
Create a
.tf
file with your infrastructure definitionRun
terraform init
to initialize your projectRun
terraform plan
to preview changesRun
terraform apply
to execute
Summary
Terraform is one of the most beginner-friendly and powerful tools in the DevOps toolbox. By embracing Infrastructure as Code, you unlock consistency, speed, scalability, and automation.
In the next post, we’ll guide you through writing your first Terraform project — step by step.
Follow this series and let’s build the cloud the right way — one block at a time.
Got questions about this post? Drop them in the comments or email me directly — happy to help!