Skip to main content

Posts

Showing posts with the label Loops and Conditionals

Loops and Conditionals: Dynamic Configurations with Count & For_Each

  Loops and Conditionals: Dynamic Configurations with Count & For_Each Your complete guide to creating flexible, DRY Terraform configurations that adapt to your infrastructure needs—without repeating yourself. 📅 Published: Feb 2026 ⏱️ Estimated Reading Time: 24 minutes 🏷️ Tags: Terraform Loops, Conditionals, Count, For_Each, Dynamic Blocks, Meta-Arguments 🎭 Introduction: The Problem of Repetition The Copy-Paste Trap Every Terraform user eventually faces this moment.  You need three subnets. So you write: hcl resource "aws_subnet" "public_1" { vpc_id = aws_vpc.main.id cidr_block = "10.0.1.0/24" availability_zone = "us-west-2a" map_public_ip_on_launch = true } resource "aws_subnet" "public_2" { vpc_id = aws_vpc.main.id cidr_block = "10.0.2.0/24" availability_zone = "us-west-2b" map_public_...