### **Installing Terraform**
#### **1. Installing Terraform on Linux**
- **Step 1: Update the Package List**
```bash
sudo apt-get update
```
- **Step 2: Install dependencies**
```bash
sudo apt-get install -y gnupg software-properties-common curl
```
- **Step 3: Add HashiCorp GPG Key**
```bash
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
```
- **Step 4: Add the HashiCorp Linux Repository**
```bash
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
```
- **Step 5: Install Terraform**
```bash
sudo apt-get update && sudo apt-get install terraform
```
- **Step 6: Verify Installation**
```bash
terraform -v
```
#### **2. Installing Terraform on Windows**
- **Step 1: Download Terraform**
- Visit the official [Terraform Downloads page](https://www.terraform.io/downloads.html) and download the Windows 64-bit package.
- **Step 2: Extract the zip**
- Extract the downloaded zip file and place `terraform.exe` in a directory of your choice (e.g., `C:\Terraform`).
- **Step 3: Add Terraform to System Path**
- Open **Control Panel > System > Advanced system settings**.
- Click on **Environment Variables**.
- Under **System Variables**, find the `Path` variable, click **Edit**, and add the directory where `terraform.exe` is located.
- **Step 4: Verify Installation**
- Open Command Prompt and run:
```cmd
terraform -v
```
---
### **Installing Terraform on CentOS**
#### **Step 1: Add HashiCorp Repository**
1. **Install required packages:**
```bash
sudo yum install -y yum-utils
```
2. **Add the HashiCorp repository:**
```bash
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
```
#### **Step 2: Install Terraform**
```bash
sudo yum -y install terraform
```
#### **Step 3: Verify Installation**
```bash
terraform -v
```
This will install Terraform on CentOS and verify that it's set up correctly.
---
### **Terraform Commands Cheat Sheet (Excel Format)**
Here's a simple format for you to use in Excel:
| **Command** | **Description** | **Example** |
|---------------------------|----------------------------------------------------------------|----------------------------------------------------|
| `terraform init` | Initializes the working directory | `terraform init` |
| `terraform validate` | Validates configuration files | `terraform validate` |
| `terraform plan` | Previews the changes that will be applied | `terraform plan` |
| `terraform apply` | Applies changes to build the infrastructure | `terraform apply` |
| `terraform destroy` | Destroys the managed infrastructure | `terraform destroy` |
| `terraform show` | Displays the current state or detailed information | `terraform show` |
| `terraform state list` | Lists all resources in the state file | `terraform state list` |
| `terraform refresh` | Updates state file based on real-world resources | `terraform refresh` |
| `terraform import` | Imports existing infrastructure into Terraform's state | `terraform import <address> <id>` |
| `terraform state rm` | Removes a resource from the state file | `terraform state rm <address>` |
| `terraform state mv` | Moves a resource in the state file | `terraform state mv <source> <destination>` |
| `terraform workspace list` | Lists available workspaces | `terraform workspace list` |
| `terraform workspace new` | Creates a new workspace | `terraform workspace new <workspace-name>` |
| `terraform workspace select`| Switches between workspaces | `terraform workspace select <workspace-name>` |
| `terraform fmt` | Formats the Terraform configuration files | `terraform fmt` |
| `terraform get -update` | Updates the modules in use to the latest version | `terraform get -update` |
| `terraform version` | Displays the current Terraform version | `terraform version` |
| `TF_LOG=DEBUG terraform apply`| Enables debug logging | `TF_LOG=DEBUG terraform apply` |
You can copy and paste this table into Excel for easy reference.
0 Comments