~/CloudSetup.In

Terraform

Infrastructure main.tf ● stable

Define and provision infrastructure as declarative, versioned code.

01 Overview

Terraform reads HCL configuration and calculates a plan to create, update, or destroy cloud resources — VPCs, compute instances, DNS records, IAM policies — across dozens of providers, keeping actual and desired state in sync.

→ official documentation

02 Installation

Pick a platform. Each step is copy-pasteable on its own.

01  Install prerequisites
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
02  Add the HashiCorp GPG key and repo
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null
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
03  Install Terraform
sudo apt-get update && sudo apt-get install -y terraform
04  Verify
terraform -version
01  Add the HashiCorp repo
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
02  Install Terraform
sudo dnf install -y terraform
03  Verify
terraform -version
01  Install via Homebrew
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
02  Verify
terraform -version
Note — commands assume sudo privileges and an up-to-date package index. Pin a specific version in production rather than tracking latest.

03 Install script

The steps above bundled into a single idempotent shell script for provisioning boxes unattended.

install-terraform.sh
Ubuntu/Debian target · safe to re-run · exits non-zero on failure
↓ download script

04 Cheatsheet

The commands reached for most often once Terraform is installed.

CommandWhat it does
terraform initDownload providers and set up the backend
terraform planPreview changes before applying
terraform applyApply changes to reach the desired state
terraform destroyTear down everything the state manages
terraform fmt -recursiveAuto-format .tf files
terraform validateCheck configuration syntax
terraform state listList resources tracked in state
terraform import addr idBring an existing resource under management