Skip to main content

🚀 Terraform Guide

📌 Introduction​

Terraform is an open-source Infrastructure as Code (IaC) tool that allows you to define, provision, and manage infrastructure using a declarative configuration language.


🛠️ Installing Terraform​

🖥️ Windows​

  1. Download Terraform from HashiCorp.
  2. Extract the binary and move it to a directory in your system's PATH.
  3. Verify installation:
    terraform version

🍏 macOS​

brew tap hashicorp/tap
brew install hashicorp/tap/terraform
terraform version

🐧 Linux​

curl -O https://releases.hashicorp.com/terraform/1.12.2/terraform_1.12.2_linux_amd64.zip
apt install -y unzip
unzip terraform_1.12.2_linux_amd64.zip -d /usr/local/bin/
terraform version

📂 Directory Setup​

mkdir -p terraform/doc
cd terraform/doc
vi main.tf

🏡 Basic Terraform Commands​

🔹 Initialize Terraform​

Create a version.tf file with the following content:

terraform {
required_version = ">= 0.13"
}

Run the initialization command:

terraform init
  • 🐂 Creates the .terraform/ directory containing provider plugins.
  • 🔐 Generates .terraform.lock.hcl to lock provider versions.

✅ Validate Configuration​

terraform validate
  • 📌 Ensures your Terraform configuration files are correctly formatted.

📚 Plan Execution​

terraform plan
  • ➕ + Resource will be created.
  • ❌ - Resource will be deleted.
  • 🔄 +/- Resource will be recreated.

🚀 Apply Changes​

terraform apply -auto-approve
  • 🏢 Provisions the infrastructure as per the configuration.

🎨 Formatting Configuration​

terraform fmt
  • 🖌 Formats Terraform configuration files.

🔍 Show Current State​

terraform show
  • 📜 Displays the current state of infrastructure.

🛡️ Destroy Infrastructure​

terraform destroy -auto-approve
  • ⚠️ Destroys all managed infrastructure.

👉 Terraform simplifies infrastructure management with declarative code. Get started today! 🚀