DEV Community

Sreya Sharma
Sreya Sharma

Posted on

Day 07: Getting Comfortable with Terraform Variables

Day 07 was all about variables, but this time I didn’t just read about them — I actually worked with them deeply. After today, Terraform code started feeling much cleaner and easier to manage.

Earlier, my configurations had many hardcoded values. Today’s learning showed me why that’s not a good idea and how variables make Terraform projects more flexible and readable.

Why Variables Matter More Than I Thought

When you’re writing small Terraform examples, hardcoding values feels fine. But as soon as a project grows, it becomes confusing very quickly.

Using variables helped me:

A

  • void repeating the same values
  • Change configurations easily
  • Write cleaner, more meaningful code

Creating a separate variables.tf file made a big difference. Everything related to inputs was in one place, and the main configuration felt much simpler.

Simple Variable Types I Worked With

I started with the basic types and used them in real resources.

  1. String: Used for names and regions.
  2. Number: Used for counts and sizes.
  3. Boolean: Helped in enabling or disabling features.
  4. List: Used when order matters.
  5. Set: Similar to a list, but without duplicate values.
  6. Tuple: Used when multiple values of different types are grouped together.
  7. Map / Dictionary: Very useful for tags and key-value data

Keeping Variables in a Separate File

Instead of spreading variables across files, I created a dedicated variables.tf file. This small change made the whole project easier to understand and maintain.

Pairing it with terraform.tfvars allowed me to change values without touching the main code, which felt very clean and professional.

What I Took Away from Day 07

  • Variables reduce hardcoding and repetition
  • Collection types make configurations flexible
  • Maps are perfect for tags and metadata
  • Separate variable files keep projects organized
  • Terraform code becomes easier to read and modify

Final Thoughts

Today’s learning made Terraform feel much more practical. Variables are not just a concept — they actually shape how clean and reusable your infrastructure code becomes.

Day 07 gave me more confidence to write Terraform projects in a structured and real-world way rather than just experimenting.

Top comments (0)