# 📘  Terraform Series – Day 4

### Terraform Workflow: init, validate, plan, apply & destroy

### <mark class="bg-yellow-200 dark:bg-yellow-500/30">🧠 Before Starting (AWS Setup)</mark>

Before using Terraform with AWS, we first need to configure AWS access on our local machine.

👉 Steps:

*   Install **AWS CLI**
    

![](https://cdn.hashnode.com/uploads/covers/685cdc0d5ca95e55fac3ab09/b7913dd3-3f8e-4c4f-ab1e-5c88ee2896ce.png align="center")

*   Configure AWS using:
    

```plaintext
aws configure
```

👉 It will ask for:

*   AWS Access Key
    
*   Secret Key
    
*   Region
    
*   Output format
    

![](https://cdn.hashnode.com/uploads/covers/685cdc0d5ca95e55fac3ab09/227acca6-c6fd-41e3-81d4-68cfbbfa7d19.png align="center")

✅ After this setup, Terraform can interact with your AWS account.

### 🎯 Objective

*   Understand Terraform workflow
    
*   Learn core commands
    
*   Perform hands-on execution
    

### 🧱 Step 0: Create Terraform Configuration File

👉 Create a file:

```plaintext
main.tf
```

![](https://cdn.hashnode.com/uploads/covers/685cdc0d5ca95e55fac3ab09/833d3314-bbbf-471d-a374-3e3e54180ccb.png align="center")

👉 This file contains your Terraform infrastructure code

### ⚙️ Step 1: Initialize Terraform

🔹 Command:

```plaintext
terraform init
```

![](https://cdn.hashnode.com/uploads/covers/685cdc0d5ca95e55fac3ab09/6c1e4c93-6752-4a11-8486-550ed16328d9.png align="center")

🔹 Purpose:

*   Initializes working directory
    
*   Downloads required providers
    
*   Prepares environment
    

### ✅ Step 2: Validate Configuration

🔹 Command:

```plaintext
terraform validate
```

🔹 Purpose:

*   Checks syntax of `.tf` files
    
*   Ensures configuration is valid
    

👉 “Check if your code is correct”

![](https://cdn.hashnode.com/uploads/covers/685cdc0d5ca95e55fac3ab09/ac81bc20-bf48-4de3-a6ba-48d0ab43242d.png align="center")

### 📊 Step 3: Review Execution Plan

🔹 Command:

```plaintext
terraform plan
```

![](https://cdn.hashnode.com/uploads/covers/685cdc0d5ca95e55fac3ab09/25c9b0de-4dad-46d9-b7bb-6a9eeac196ad.png align="center")

🔹 Purpose:

*   Shows what Terraform will do
    
*   Lists resources to create/change/destroy
    
*   Works as a dry run
    

👉 “Preview before execution”

### 🚀 Step 4: Apply Configuration

🔹 Command:

```plaintext
terraform apply
```

🔹 Purpose:

*   Executes the plan
    
*   Creates real infrastructure
    

👉 Type `yes` to confirm

![](https://cdn.hashnode.com/uploads/covers/685cdc0d5ca95e55fac3ab09/522bdc22-eeb6-4cb8-ad73-8a315cc9e218.png align="center")

### 🧨 Step 5: Destroy Infrastructure

🔹 Command:

```plaintext
terraform destroy
```

🔹 Purpose:

*   Deletes all resources
    
*   Avoids unnecessary cloud cost
    

![](https://cdn.hashnode.com/uploads/covers/685cdc0d5ca95e55fac3ab09/89dd273c-f629-4eb3-936e-de1527a54758.png align="center")

### ⚡ Auto-Approve Option

```plaintext
terraform apply -auto-approve
terraform destroy -auto-approve
```

👉 Skips confirmation

👉 Useful in automation (CI/CD)

## **👨‍💻 About the Author**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1751797710818/123a7231-3dca-4273-ad68-7bd026f69b95.png?auto=compress,format&format=webp&auto=compress,format&format=webp&auto=compress,format&format=webp&auto=compress,format&format=webp&auto=compress,format&format=webp align="center")

“A complete Terraform series covering everything from fundamentals to advanced real-world infrastructure automation in a DevOps environment.”

### **📬 Let's Stay Connected**

*   📧 **Email**: [**gujjarapurv181@gmail.com**](mailto:gujjarapurv181@gmail.com)
    
*   🐙 **GitHub**: [**github.com/ApurvGujjar07**](http://github.com/ApurvGujjar07)
    
*   💼 **LinkedIn**: [**linkedin.com/in/apurv-gujjar**](http://linkedin.com/in/apurv-gujjar)
