← Back to blog
21 March 20263 min read

Terraform Basics Getting Started with Infrastructure as Code

A beginner-friendly guide to understanding Terraform, its core concepts, and how to provision infrastructure efficiently using code.

TerraformTerraformInfrastructure as CodeDevOpsCloud

Terraform Basics: Getting Started with Infrastructure as Code

Terraform is one of the most popular tools for managing infrastructure using code. Instead of manually creating resources in cloud platforms, Terraform allows you to define everything declaratively and version it just like application code.

In this article, we’ll walk through the fundamentals of Terraform and how to get started.

What is Terraform?

Terraform is an Infrastructure as Code (IaC) tool developed by HashiCorp. It allows you to define and provision infrastructure using a simple configuration language called HCL (HashiCorp Configuration Language).

With Terraform, you can manage: • AWS, Azure, GCP resources • Kubernetes clusters • Databases • Networking • And much more

Why Use Terraform?

Here are some key benefits:

  1. Declarative Configuration

You define what you want, not how to do it.

resource "aws_s3_bucket" "example" {
  bucket = "my-bucket"
}
  1. Version Control

Infrastructure changes can be tracked via Git, just like application code.

  1. Reusability

Modules allow you to reuse infrastructure patterns.

  1. Multi-Cloud Support

Terraform works across multiple cloud providers with the same workflow.

Core Concepts

  1. Provider

A provider is responsible for interacting with APIs (AWS, Azure, etc.).

provider "aws" {
  region = "ap-southeast-2"
}

  1. Resource

A resource defines a piece of infrastructure.

resource "aws_instance" "example" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
}

  1. Variables

Variables make your configuration flexible.

variable "instance_type" {
  default = "t2.micro"
}

  1. Outputs

Outputs expose useful information after deployment.

output "instance_ip" {
  value = aws_instance.example.public_ip
}

  1. State

Terraform keeps track of infrastructure using a state file (terraform.tfstate).

This helps Terraform: • Know what exists • Detect changes • Avoid duplications

Terraform Workflow

The typical workflow includes 4 steps:

  1. Initialize
terraform init

Downloads providers and initializes the project.

  1. Plan
terraform plan

Shows what Terraform will do before applying changes.

  1. Apply
terraform apply

Executes the plan and provisions infrastructure.

  1. Destroy
terraform destroy

Removes all resources defined in the configuration.

Example: Simple AWS EC2 Setup

provider "aws" {
  region = "ap-southeast-2"
}

resource "aws_instance" "web" {
  ami           = "ami-123456"
  instance_type = "t2.micro"

  tags = {
    Name = "terraform-example"
  }
}

Run:

terraform init
terraform plan
terraform apply

Best Practices • Use remote state (S3 + DynamoDB for AWS) • Organize code with modules • Keep configs small and reusable • Avoid hardcoding values → use variables • Use .tfvars for environment configs

When Should You Use Terraform?

Terraform is ideal when: • You manage cloud infrastructure • You want reproducibility • You need consistent environments (dev/staging/prod) • You work in a DevOps or microservices architecture

Conclusion

Terraform is a powerful tool that brings automation, consistency, and scalability to infrastructure management. Once you understand the basics—providers, resources, and workflow—you can start building more complex systems with confidence.

If you’re a software engineer moving into DevOps or cloud, Terraform is a must-have skill.

Support My Work

If you've enjoyed my content and found it helpful, consider buying me a coffee. It keeps me caffeinated and creating!

Buy me a coffee