Terraform Introduction

Summary: in this tutorial, you will learn start with terraform basics by installing the cli, writing your first configuration, and applying infrastructure changes safely.

Terraform Introduction

Terraform lets you define infrastructure using configuration files and apply it consistently across environments.

What Terraform does

Terraform works by:

  • Reading your configuration files
  • Comparing desired state to actual state
  • Creating a plan of changes
  • Applying changes in the correct order

Install Terraform

Download the official package from https://www.terraform.io and install the CLI for your platform.

Verify the install:

terraform version

Write your first configuration

Create a file named main.tf:

terraform {
  required_providers {
    local = {
      source  = "hashicorp/local"
      version = "~> 2.0"
    }
  }
}
 
provider "local" {}
 
resource "local_file" "example" {
  content  = "Hello from Terraform!"
  filename = "hello.txt"
}

Initialize and apply

Run:

terraform init
terraform apply -auto-approve

This creates hello.txt locally and stores state in terraform.tfstate.

Why this matters

Terraform makes infrastructure changes predictable and repeatable. Instead of running commands manually, you store infrastructure as code and apply the same configuration reliably every time.

Was this page helpful?
SR

Written by the ShellRAG Team

The ShellRAG editorial team writes practical, beginner-friendly Terraform tutorials with tested code examples and real-world use cases. Every article is technically reviewed for accuracy and updated regularly.

Learn more about us →