🚀 Day 3: Terraform in the Wild – My First Real Resources
Moving From Theory to Action
After two days of setup and fundamentals, Day 3 finally felt real. The original task was simple—create an S3 bucket—but I wanted to go beyond the basics.
Instead of provisioning only a bucket, I turned the exercise into a mini-experiment to understand how Terraform handles resource dependencies. And honestly? This is the day Terraform really clicked for me.
💡 The “Aha!” Moment: State and Drift
Terraform compares:
- Desired state → defined in your
.tffiles - Actual state → what already exists in AWS
If something is changed manually in AWS, Terraform detects drift and proposes the exact steps to reconcile the system. You don’t need manual “if exists” logic — Terraform treats your code as the source of truth.
🧠My Experiment: Testing Terraform’s Dependency Logic
I asked myself:
“What happens if one resource indirectly depends on another?”
To test this, I created:
- a VPC, and
- an S3 bucket tagged with the VPC’s ID
This creates an implicit dependency:
The VPC must exist before Terraform can assign its ID to the bucket tags.
Would Terraform figure this out automatically?
đź§© The Code
Everything was placed inside main.tf.
I intentionally avoided using depends_on because I wanted Terraform to infer the relationship itself.
resource "aws_vpc" "my_vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "day3-experiment-vpc"
}
}
resource "aws_s3_bucket" "my_bucket" {
bucket = "my-unique-day3-bucket-experiment" # Must be globally unique
tags = {
Name = "My bucket"
Environment = "Dev"
# 🪄 Implicit dependency: Terraform knows this must come after the VPC
OriginVpcId = aws_vpc.my_vpc.id
}
}
By referencing aws_vpc.my_vpc.id, Terraform automatically understands that:
The VPC must be created first
The S3 bucket should be created after the VPC ID becomes available
No manual dependency flags required.
📝 Key Takeaways Implicit dependencies keep code clean. Referencing resources is enough for Terraform to determine execution order.
Terraform’s graph is deterministic. You can trust it to build in the right sequence.
Workflow matters. init → plan → apply → destroy keeps your IaC lifecycle predictable.
IaC builds confidence. Seeing your infrastructure defined entirely in code feels empowering.