0% found this document useful (0 votes)
3 views7 pages

Linux Terraform Git Beginner Guide

This document is a beginner's guide for using Linux, Terraform, and Git, specifically tailored for Debian Linux users. It provides step-by-step instructions on basic Linux commands, installing Terraform, writing Terraform code for creating a Google Cloud Platform Debian VM, and managing Git for version control. The guide also includes summary commands for quick reference in Linux, Terraform, and Git.

Uploaded by

prakjp17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Linux Terraform Git Beginner Guide

This document is a beginner's guide for using Linux, Terraform, and Git, specifically tailored for Debian Linux users. It provides step-by-step instructions on basic Linux commands, installing Terraform, writing Terraform code for creating a Google Cloud Platform Debian VM, and managing Git for version control. The guide also includes summary commands for quick reference in Linux, Terraform, and Git.

Uploaded by

prakjp17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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 main.tf variables.tf outputs.tf README.md

# Edit a file (nano editor)


nano README.md
# (write a line like: "My Terraform project practice" then Ctrl+O to save and Ctrl+X to exit)

# View file contents


cat README.md

# Remove files or folders


rm README.md
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 main.tf

# Change ownership (replace 'user' with your username)


sudo chown user:user main.tf

Step 3: Install Terraform on Debian


sudo apt update
sudo apt install -y gnupg software-properties-common curl

# Add HashiCorp GPG key


curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o
/usr/share/keyrings/hashicorp-archive-keyring.gpg

# Add HashiCorp repo


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

# Verify install
terraform -v

Step 4: Write Your First Terraform Code (Create GCP Debian VM)
cd ~/practice/terraform_project/code

# Create main.tf
nano main.tf

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.debian-instance.name
}

Step 5: Initialize and Apply Terraform


terraform init
terraform validate
terraform plan -out=plan.tfplan
terraform apply plan.tfplan

# Type "yes" to confirm apply.

Step 6: Create Terraform Module


mkdir -p ../modules/instance
cd ../modules/instance

nano main.tf
Paste:

resource "google_compute_instance" "debian_instance" {


name = var.instance_name
machine_type = var.machine_type
zone = var.zone

boot_disk {
initialize_params {
image = var.disk_image
size = var.disk_size
}
}

network_interface {
network = "default"
access_config {}
}
}

Create variables.tf:

nano variables.tf

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 outputs.tf:

nano outputs.tf

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 main.tf

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy