# Day 128: Debugging Terraform Issues & Understanding Variables

Today, I explored **Terraform debugging techniques** and deep-dived into one of its most powerful features — **variables and expressions**. Managing infrastructure with Terraform often involves identifying configuration issues and making setups dynamic using variables.

---

### 🧩 **Debugging Terraform Issues**

Even the best-written Terraform configurations can run into errors — syntax issues, dependency conflicts, or provider mismatches. Here are some of the tools and strategies I learned:

* `TF_LOG` environment variable – Enables detailed logs at various levels (`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`).
    
* `terraform plan` & `terraform validate` – Used for catching errors early before any changes are applied.
    
* **Terraform graph** – Helps visualize dependencies between resources to identify circular references.
    
* **Check provider versions** – Mismatched or outdated providers can often cause unexpected issues.
    

🧠 **Tip:** Always start debugging by enabling logs and validating configurations — this saves a lot of time.

---

### ⚙️ **Terraform Variables & Expressions**

Variables make Terraform configurations **reusable**, **scalable**, and **flexible**.

#### **1️⃣ Input Variables (**`variable`)

Input variables act like parameters for your Terraform modules.  
They allow you to customize infrastructure without changing the core code.

```haskell
variable "instance_type" {
  description = "EC2 instance type"
  default     = "t2.micro"
}
```

You can override these values through CLI flags, `.tfvars` files, or environment variables.

#### **2️⃣ Output Variables (**`output`)

Output variables help share data between configurations or display key information after deployment.

```haskell
output "instance_ip" {
  description = "Public IP of the EC2 instance"
  value       = aws_instance.web.public_ip
}
```

These outputs are super helpful for automation scripts or when chaining multiple Terraform projects.

---

### 🚀 **Key Takeaways**

* **Debugging is essential** for maintaining stable and predictable IaC workflows.
    
* **Input variables** make configurations flexible, and **output variables** improve visibility and integration.
    
* Mastering these tools turns Terraform from a simple declarative tool into a **powerful automation framework**.
    

Terraform gives you control, but understanding how to **debug and parameterize** makes you unstoppable.
