Posts

Day 13 - Terraform Data Sources

Image
Today’s learning felt like a shift from “building everything” to working intelligently with what already exists . Until now, most of my Terraform work was about creating infrastructure. But in real-world cloud environments, things are rarely that simple. Networks, security layers, and shared resources are often already in place, managed by different teams. This is where Terraform data sources come in. What Are Terraform Data Sources Terraform data sources allow us to read existing infrastructure instead of creating it. A simple way to think about it: Resources → Create and manage infrastructure Data Sources → Read and reference existing infrastructure This distinction is small in syntax, but huge in real-world usage. Scenario for This Demo In this lab, I simulated a real-world setup: A shared VPC already exists A shared subnet already exists My job is to launch an EC2 instance inside that network The key rule: I should NOT recreate the VPC or subnet I sho...

Day 12 - Terraform Functions Part 2

Image
Today I continued my Terraform journey by working with advanced built-in functions. Day 11 focused on transforming values for resources. Day 12 focused on validating inputs, handling files, securing data, and preparing values before they are used. The biggest realization today was: Not everything in Terraform creates AWS resources. Some parts only process data. Understanding the Flow Terraform works in layers: terraform.tfvars → locals.tf → main.tf → outputs.tf Inputs come from terraform.tfvars Functions process data in locals.tf Resources are created in main.tf Results are displayed using outputs.tf Some assignments only use the first 3 steps and never reach AWS . What I Learned Backup Validation I used endswith() in variable validation. This prevents invalid values before Terraform even runs a plan. This happens before any AWS resource is created. validation error when backup name is wrong Sensitive Data I marked outputs as sensitive = true . This...

Day 11 - Terraform Functions Part 1

Image
Today I worked on Day 11 of my AWS Terraform learning journey. The focus was Terraform built-in functions and how they help clean, transform, validate, and reuse values inside infrastructure code. Terraform functions are small but powerful helpers. They are not custom functions like in Python or JavaScript. Instead, they are built into Terraform and can be used inside expressions to produce better names, cleaner tags, validated inputs, dynamic lists, and reusable configurations. For this day, I focused on six practical assignments. What I Built In this hands-on lab, I created: A VPC with merged tags An S3 bucket with a cleaned and formatted bucket name A security group with ports generated from a comma-separated variable An EC2 instance with instance type selected by environment Input validation for instance type format Outputs to clearly show how each function transformed the values Functions Covered lower() The lower() function converts text into lowercase. I used it t...

Day 10 - Terraform Dynamic Blocks, Conditional Expressions, and Splat Expressions

Image
There is a moment in learning Terraform where it stops feeling like writing static code, and starts feeling like shaping logic. Day 10 was that moment for me. Until now, I was defining resources directly. Today, I learned how to make Terraform think, repeat intelligently, and extract data cleanly . The three pillars of today’s learning: Conditional Expressions Dynamic Blocks Splat Expressions What I Built To understand these concepts, I created a simple but meaningful setup: S3 buckets with environment-based logic A security group with multiple ingress rules Outputs that collect values dynamically Nothing too fancy. But powerful enough to understand how real-world Terraform becomes scalable. Conditional Expressions What It Means Conditional expressions allow Terraform to choose values based on conditions. Simple idea: If something is true → use one value If not → use another Example I Used bucket_count = var.environment == "prod" ? 2 : 1 This means:...