All posts
What Is Terraform? A Quick Overview
terraformdevopscloud

What Is Terraform? A Quick Overview

Quang Tran D.'s avatarQuang Tran D.
Table of Contents6 sections

Terraform is an Infrastructure as Code (IaC) tool built by HashiCorp that lets you build, change, and manage infrastructure through configuration files instead of manual console clicks. Rather than provisioning servers one click at a time, you write code describing the infrastructure you want, and Terraform handles the rest.

Why Use Terraform?

  • Cloud-agnostic: works across AWS, Azure, GCP, Kubernetes, and more — unlike CloudFormation, which is locked to AWS.

  • Declarative: you describe the desired end state (e.g., "I want 5 servers"), and Terraform figures out how to get there.

  • Version control: infrastructure configs live as code, so changes are tracked and auditable over time.

  • Immutable infrastructure: instead of patching a running server, Terraform typically replaces it with a new one, avoiding configuration drift.

  • Reusable modules: infrastructure patterns can be packaged into modules and reused across teams (e.g., a standard "Web Server" module).

Core Components

  1. Core (engine): the local engine that reads your configuration and compares it against the current state to determine what needs to change.

  2. Providers: plugins that translate Terraform code into API calls for each platform (AWS, Azure, Kubernetes, etc.).

  3. State file (terraform.tfstate): Terraform's "memory," mapping code to real-world resources. In team environments, this file is usually stored remotely (e.g., in AWS S3) so everyone works off the same source of truth.

Common Terraform Commands

Command

Purpose

terraform init

Initializes the working directory and downloads required providers

terraform plan

Previews the changes that will be applied

terraform apply

Executes the changes against real infrastructure

terraform destroy

Tears down all resources created

A Simple Example

The snippet below provisions an EC2 instance on AWS:

provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "my_web_server" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"

  tags = {
    Name = "DevOps-Server"
  }
}

Terraform uses HCL (HashiCorp Configuration Language) — human-readable and easy for tools to parse.

Terraform vs. Other Tools

  • vs. CloudFormation: Terraform is multi-cloud with a cleaner HCL syntax compared to JSON/YAML; CloudFormation is AWS-only but manages state automatically.

  • vs. Ansible: Terraform focuses on provisioning infrastructure and tracking it via state/plan; Ansible focuses more on configuration management and app deployment, executing tasks immediately without maintaining state.

Conclusion

Terraform makes infrastructure management automated, consistent, and scalable — a popular choice for DevOps teams working across multiple cloud platforms.

Reference:

GeeksforGeeks - Introduction to Terraform

Terraform