Initial Setup
Get Terraform installed and create your first infrastructure. This guide walks you through installation and provisioning your first resources.
π― What You’ll Accomplish
By the end of this tutorial, you’ll have:
- β Terraform installed and verified
- β Your first Terraform configuration
- β Infrastructure provisioned and destroyed
π Prerequisites
- Windows, macOS, or Linux
- Cloud account (AWS, Azure, or GCP) for deployment examples
- Basic command line familiarity
πΎ Step 1: Install Terraform
macOS
brew tap hashicorp/tap
brew install hashicorp/tap/terraformLinux
wget -O- 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 terraformWindows
choco install terraformVerify Installation
terraform --versionπ Step 2: Create Your First Configuration
Create main.tf:
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "~> 2.0"
}
}
}
resource "local_file" "hello" {
content = "Hello, Terraform!"
filename = "${path.module}/hello.txt"
}
output "file_content" {
value = local_file.hello.content
}π Step 3: Initialize and Apply
terraform init
terraform plan
terraform applyType yes when prompted.
Check the created file:
cat hello.txtπ§Ή Step 4: Destroy Infrastructure
terraform destroyType yes when prompted.
β Verification Checklist
Before moving forward, verify:
-
terraform --versionshows Terraform installed -
terraform initcompletes successfully -
terraform applycreates resources -
terraform destroyremoves resources
π You’re Done!
You’ve successfully installed Terraform and provisioned your first infrastructure.
π What’s Next?
Quick learner: Terraform Quick Start
Code-first learner: Terraform By Example
Last updated