Instalasi #
Terraform didistribusikan sebagai single binary — tidak ada dependency runtime, tidak ada JVM, tidak ada container engine yang perlu diinstall terpisah. Kamu download satu file, jalankan, dan langsung bisa bekerja. Kesederhanaan distribusi ini adalah salah satu alasan Terraform begitu populer — barrier to entry-nya sangat rendah. Bagian ini memandu proses instalasi di macOS, Linux, dan Windows, serta cara mengelola beberapa versi Terraform secara bersamaan.
Memilih Metode Instalasi #
Ada beberapa cara untuk menginstall Terraform. Pilihannya tergantung OS yang kamu gunakan dan apakah kamu perlu mengelola beberapa versi sekaligus.
flowchart TD
A["Install Terraform"] --> B{"OS?"}
B -->|"macOS"| C{"Punya\nHomebrew?"}
B -->|"Linux"| D{"Distro?"}
B -->|"Windows"| E{"Punya\nWinget?"}
C -->|"Ya"| F["brew install\nhashicorp/tap/terraform\n✅ Paling mudah"]
C -->|"Tidak"| G["Download binary\ndari releases.hashicorp.com"]
D -->|"Debian/Ubuntu"| H["apt repository\nresmi HashiCorp"]
D -->|"RHEL/Fedora"| I["yum repository\nresmi HashiCorp"]
D -->|"Lainnya"| J["Download binary\ndari releases.hashicorp.com"]
E -->|"Ya"| K["winget install\nHashiCorp.Terraform"]
E -->|"Tidak"| L["choco install\nterraform"]
A --> M{"Perlu multi-versi?"}
M -->|"Ya"| N["Install tfenv\nlalu tfenv install <version>"]
M -->|"Tidak"| O["Pilih metode di atas"]
style F fill:#e8f5e9,stroke:#2e7d32
style H fill:#e8f5e9,stroke:#2e7d32
style K fill:#e8f5e9,stroke:#2e7d32
style N fill:#e3f2fd,stroke:#1565c0| Metode | OS | Kelebihan | Kekurangan |
|---|---|---|---|
| Homebrew | macOS | Paling mudah, auto-update | Butuh Homebrew |
| apt/yum repo | Linux | Terintegrasi package manager | Butuh setup repo |
| Winget | Windows | Native Windows package manager | Tidak semua Windows support |
| Chocolatey | Windows | Populer, stabil | Butuh install Chocolatey |
| Binary manual | Semua | Tidak butuh apapun | Update manual |
| tfenv | macOS/Linux | Multi-versi, auto-switch | Butuh install tfenv |
Instalasi di macOS #
Cara paling nyaman di macOS adalah menggunakan Homebrew. Jika belum punya Homebrew, install dulu dari brew.sh.
# Menggunakan Homebrew (direkomendasikan)
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
# Verifikasi instalasi
terraform version
# Terraform v1.6.x
# on darwin_arm64
# Update ke versi terbaru
brew upgrade hashicorp/tap/terraform
Jika tidak menggunakan Homebrew, download binary langsung dari halaman release resmi.
# Download binary langsung
# Cek versi terbaru di: https://releases.hashicorp.com/terraform/
TF_VERSION="1.6.6"
curl -LO "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_darwin_arm64.zip"
unzip "terraform_${TF_VERSION}_darwin_arm64.zip"
sudo mv terraform /usr/local/bin/
rm "terraform_${TF_VERSION}_darwin_arm64.zip"
Instalasi di Linux #
Di Linux, gunakan repository resmi HashiCorp untuk mendapatkan update yang mudah melalui package manager.
Ubuntu / Debian #
# Tambah GPG key resmi HashiCorp
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null
# Tambah repository
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
# Install
sudo apt update && sudo apt install terraform
# Verifikasi
terraform version
CentOS / RHEL / Fedora #
# Tambah repository resmi
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
# Install
sudo yum -y install terraform
# Verifikasi
terraform version
Binary Manual (Semua Distro Linux) #
# Download dan install binary langsung
TF_VERSION="1.6.6"
curl -LO "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip"
unzip "terraform_${TF_VERSION}_linux_amd64.zip"
sudo mv terraform /usr/local/bin/
rm "terraform_${TF_VERSION}_linux_amd64.zip"
# Verifikasi
terraform version
Instalasi di Windows #
Di Windows, gunakan Winget (package manager bawaan Windows 11) atau Chocolatey.
# Menggunakan Winget (Windows 11+)
winget install HashiCorp.Terraform
# Menggunakan Chocolatey
choco install terraform
# Atau manual:
# 1. Download zip dari https://releases.hashicorp.com/terraform/
# 2. Extract terraform.exe
# 3. Pindahkan ke direktori yang ada di PATH
# (misalnya C:\terraform, lalu tambah ke System PATH)
# Verifikasi (di PowerShell atau Command Prompt)
terraform version
Setelah install manual di Windows, pastikan direktori tempat terraform.exe berada sudah ditambahkan ke System PATH agar bisa diakses dari terminal manapun. Buka System Properties → Environment Variables → Path → Edit → New, lalu tambahkan path direktori tersebut.Mengelola Multiple Versi dengan tfenv #
Di dunia nyata, kamu mungkin bekerja di beberapa proyek Terraform yang masing-masing menggunakan versi berbeda. Proyek lama mungkin masih di v1.3, proyek baru di v1.6. Beralih manual antar versi adalah resep untuk frustrasi. tfenv memecahkan masalah ini — ia adalah version manager untuk Terraform, mirip dengan nvm untuk Node.js atau pyenv untuk Python.
# Install tfenv di macOS
brew install tfenv
# Install tfenv di Linux
git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv
echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# Untuk zsh: ~/.zshrc
Setelah tfenv terinstall, kamu bisa mengelola beberapa versi Terraform dengan mudah.
# Lihat semua versi yang tersedia
tfenv list-remote
# Install beberapa versi
tfenv install 1.6.6
tfenv install 1.5.7
tfenv install latest
# Aktifkan versi tertentu secara global
tfenv use 1.6.6
# Lihat versi yang sudah diinstall
tfenv list
Fitur paling powerful dari tfenv adalah per-project version pinning. Cukup buat file .terraform-version di root proyek, dan tfenv akan otomatis menggunakan versi yang tepat saat kamu berada di direktori tersebut.
# Di root proyek A (menggunakan Terraform 1.6)
echo "1.6.6" > .terraform-version
# Di root proyek B (menggunakan Terraform 1.5)
echo "1.5.7" > .terraform-version
# Saat kamu cd ke proyek A:
$ terraform version
Terraform v1.6.6
# Saat kamu cd ke proyek B:
$ terraform version
Terraform v1.5.7
# Otomatis berpindah versi tanpa konfigurasi manual!
flowchart LR
A["Project A\n.terraform-version = 1.6.6"] --> C["tfenv"]
B["Project B\n.terraform-version = 1.5.7"] --> C
C --> D["terraform v1.6.6\nsaat di Project A"]
C --> E["terraform v1.5.7\nsaat di Project B"]
style A fill:#e3f2fd,stroke:#1565c0
style B fill:#fff3e0,stroke:#e65100
style D fill:#e8f5e9,stroke:#2e7d32
style E fill:#e8f5e9,stroke:#2e7d32Commit file .terraform-version ke version control. Ini memastikan semua anggota tim menggunakan versi Terraform yang sama untuk setiap proyek — menghindari “works on my machine” yang disebabkan perbedaan versi.Verifikasi Instalasi #
Setelah instalasi, verifikasi bahwa semuanya berjalan dengan benar.
# Cek versi
terraform version
# Terraform v1.6.6
# on darwin_arm64
# Cek lokasi binary
which terraform
# /opt/homebrew/bin/terraform (macOS Homebrew)
# /usr/local/bin/terraform (Linux manual)
# Cek bahwa help berfungsi
terraform help
# Menampilkan daftar subcommand
# Cek help untuk subcommand spesifik
terraform help plan
# Menampilkan flag dan opsi untuk terraform plan
# Aktifkan tab completion untuk pengalaman CLI yang lebih nyaman
terraform -install-autocomplete
# Restart terminal setelahnya
# Sekarang kamu bisa mengetik:
# terraform pl<TAB> → terraform plan
# terraform app<TAB> → terraform apply
Verifikasi Instalasi #
Setelah menginstal Terraform, verifikasi bahwa instalasi berfungsi dengan benar.
# Cek versi
terraform version
# Terraform v1.6.3
# on darwin_arm64
# Cek bahwa binary bisa dijalankan
terraform --help
# Menampilkan daftar perintah yang tersedia
# Cek provider plugin
terraform providers
# Menampilkan provider yang diperlukan oleh konfigurasi saat ini
# Test sederhana: buat file test dan jalankan
mkdir test-install && cd test-install
echo 'output "hello" { value = "Terraform is working!" }' > main.tf
terraform init
terraform output
# hello = "Terraform is working!"
rm -rf test-install
# Troubleshooting umum:
# Error: "terraform: command not found"
# → PATH belum dikonfigurasi dengan benar
echo $PATH | tr ':' '
' | grep terraform
# Error: "Error: Incompatible Terraform version"
# → Versi Terraform tidak kompatibel dengan konfigurasi
# → Cek required_version di terraform block
terraform version
# Error: "Error: Failed to install provider"
# → Masalah jaringan atau registry tidak bisa diakses
terraform init -plugin-dir=/path/to/plugins
Version Management #
# Mengelola beberapa versi Terraform dengan tfenv (macOS/Linux)
brew install tfenv
tfenv install 1.6.3
tfenv install 1.5.7
tfenv use 1.6.3
terraform version # Terraform v1.6.3
# Atau dengan tenv (alternatif yang lebih baru)
brew install tenv
tenv tofu install latest
tenv terraform install 1.6.3
# Versi pinning di project
# .terraform-version file:
echo "1.6.3" > .terraform-version
# Tool akan otomatis gunakan versi ini
# Cek compatibility
terraform version -json | jq '.terraform_version'
# Di konfigurasi, pin versi minimum
terraform {
required_version = ">= 1.6.0, < 2.0.0"
# Pastikan team menggunakan versi yang kompatibel
}
Platform-Specific Installation #
# macOS dengan Homebrew (recommended)
brew tap hashicorp/tap
brew install hashicorp/terraform
brew upgrade hashicorp/terraform
# Linux (Debian/Ubuntu)
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 terraform
# Windows dengan Chocolatey
choco install terraform
# Verify installation
terraform version
terraform --help
Version Manager (tfenv) #
# tfenv: Terraform version manager
# Install
brew install tfenv
# Install specific version
tfenv install 1.6.0
tfenv install 1.5.5
# Set default version
tfenv use 1.6.0
# List installed versions
tfenv list
# List available versions
tfenv list-remote
# .terraform-version file di project root
echo "1.6.0" > .terraform-version
# tfenv akan otomatis switch ke versi ini
# Alternatif: tgswitch (untuk Terragrunt + Terraform)
brew install warrensbox/tap/tgswitch
# Atau: tenv (support Terraform, Terragrunt, OpenTofu)
brew install tenv
Ringkasan #
- Terraform adalah single binary — tidak ada dependency runtime, bisa diinstall di macOS, Linux, dan Windows dalam hitungan detik.
- Gunakan package manager (Homebrew, apt, yum, Winget, Chocolatey) untuk instalasi dan update yang mudah — hindari download manual kecuali terpaksa.
- tfenv untuk multi-versi — jika bekerja di beberapa proyek yang menggunakan versi Terraform berbeda, tfenv mengelola switching secara otomatis.
.terraform-versionmemungkinkan pin versi per-proyek — commit file ini ke version control agar semua anggota tim konsisten.- Aktifkan tab completion (
terraform -install-autocomplete) untuk mempercepat pengetikan command.- Verifikasi instalasi dengan
terraform versiondan pastikan binary ada di PATH.