Linux, Terraform & Git Beginner Guide
Stepwise practical commands and explanations for Debian Linux users.
Step 1: Linux Basics — Navigation & File Management
# Show current folder
pwd
# List files and folders (long format)
ls -l
# Change directory to root (requires sudo)
sudo -i
cd /root
# Or go back to your home folder as normal user
exit # exit root
cd ~
# Create folders for practice
mkdir -p ~/practice/terraform_project/code
cd ~/practice/terraform_project/code
# Create empty files
touch [Link] [Link] [Link] [Link]
# Edit a file (nano editor)
nano [Link]
# (write a line like: "My Terraform project practice" then Ctrl+O to save and Ctrl+X to exit)
# View file contents
cat [Link]
# Remove files or folders
rm [Link]
rm -r ~/practice/terraform_project # CAREFUL: deletes folder recursively
Step 2: Manage Linux File Permissions
# List files with permissions
ls -l
# Change permissions to rwxr-xr-x (755)
chmod 755 [Link]
# Change ownership (replace 'user' with your username)
sudo chown user:user [Link]
Step 3: Install Terraform on Debian
sudo apt update
sudo apt install -y gnupg software-properties-common curl
# Add HashiCorp GPG key
curl -fsSL [Link] | sudo gpg --dearmor -o
/usr/share/keyrings/[Link]
# Add HashiCorp repo
echo "deb [signed-by=/usr/share/keyrings/[Link]]
[Link] $(lsb_release -cs) main" | sudo tee
/etc/apt/[Link].d/[Link]
sudo apt update
sudo apt install terraform
# Verify install
terraform -v
Step 4: Write Your First Terraform Code (Create GCP Debian VM)
cd ~/practice/terraform_project/code
# Create [Link]
nano [Link]
Paste this code (replace <YOUR_GCP_PROJECT_ID>):
provider "google" {
project = "<YOUR_GCP_PROJECT_ID>"
region = "us-central1"
zone = "us-central1-a"
}
resource "google_compute_instance" "debian-instance" {
name = "debian-vm-instance"
machine_type = "e2-medium"
zone = "us-central1-a"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
size = 10
}
}
network_interface {
network = "default"
access_config {}
}
}
output "instance_name" {
value = google_compute_instance.[Link]
}
Step 5: Initialize and Apply Terraform
terraform init
terraform validate
terraform plan -out=[Link]
terraform apply [Link]
# Type "yes" to confirm apply.
Step 6: Create Terraform Module
mkdir -p ../modules/instance
cd ../modules/instance
nano [Link]
Paste:
resource "google_compute_instance" "debian_instance" {
name = var.instance_name
machine_type = var.machine_type
zone = [Link]
boot_disk {
initialize_params {
image = var.disk_image
size = var.disk_size
}
}
network_interface {
network = "default"
access_config {}
}
}
Create [Link]:
nano [Link]
variable "instance_name" {
type = string
}
variable "machine_type" {
type = string
default = "e2-medium"
}
variable "zone" {
type = string
default = "us-central1-a"
}
variable "disk_image" {
type = string
default = "debian-cloud/debian-11"
}
variable "disk_size" {
type = number
default = 10
}
Create [Link]:
nano [Link]
output "instance_id" {
value = google_compute_instance.debian_instance.id
}
output "instance_name" {
value = google_compute_instance.debian_instance.name
}
Step 7: Use the Module in Root Config
cd ~/practice/terraform_project/code
nano [Link]
Replace resource block with:
provider "google" {
project = "<YOUR_GCP_PROJECT_ID>"
region = "us-central1"
zone = "us-central1-a"
}
module "debian_instance" {
source = "../modules/instance"
instance_name = "my-debian-instance"
machine_type = "e2-medium"
zone = "us-central1-a"
disk_image = "debian-cloud/debian-11"
disk_size = 10
}
Step 8: Run Terraform for Module
terraform init
terraform plan
terraform apply
Step 9: Initialize Git and Track Your Terraform Code
cd ~/practice/terraform_project
# Initialize git repo
git init
# Add all files
git add .
# Commit files
git commit -m "Initial commit - Terraform Debian VM code and modules"
# Check status
git status
Step 10: Summary Commands to Remember
# Linux Navigation and File Operations
pwd
ls -l
cd foldername
mkdir foldername
touch filename
nano filename
sudo command
# Terraform Commands
terraform init
terraform validate
terraform plan
terraform apply
terraform destroy
# Git Commands
git init
git add filename
git commit -m "message"
git status
git log