My First 3 Days of Learning Terraform
SUCCESS ISN'T OVERNIGHT. IT'S WHEN EVERY DAY YOU GET A LITTLE BETTER THAN THE DAY BEFORE. ITS ALL ADDS UP.
Hey everyone! π
I recently started learning Terraform, and I wanted to share my progress over the first 3 days.
- What & why we use Terraform?
Terrafrom is a tool for building, changing and managing infrastructure in a safe and efficient way. It is also known as Infrastructure as a code because, where you can write a code to define and manage your infrastructure instead of manually configuring it.
One of the first things I learned was the difference between Terraform and Ansible.
Terraform vs Ansible
Terraform : Terraform is mainly used for provisioning infrastructure (like launching EC2, creating VPCs, etc.).
Ansible : Ansible is focused more on configuring servers and automating tasks after the infrastructure is ready.
Terraform vs AWS CloudFormation
| Terraform | CloudFormation |
1. Supports multiple cloud providers (AWS, Azure, GCP, GitHub, Kubernetes, etc.) | 1. Built by AWS and works only with AWS resources |
2. Ideal for multi-cloud or hybrid cloud projects | 2. Suitable if you're using AWS only |
3. Uses HCL (HashiCorp Configuration Language) β clean, readable, beginner-friendly | 3. Uses JSON/YAML β can become long and complex |
4. Manages infrastructure state via a state file (more visibility and control) | 4. State is managed internally by AWS (less transparency) |
5. Large open-source community, many reusable modules and examples | Limited community support, reusable templates but fewer resources |
6. Widely adopted due to flexibility and provider neutrality | Preferred mostly by AWS-focused teams |
Understanding Blocks and Labels
Blocks : Blocks are the building pieces of Terraform code like
resource,provider,variable, etc.Labels : Labels help identify and categorize those blocks.
Basic Syntax :-
// Block βLabelβ βLabelβ {
values = β β
}
Basic Syntax for Json Format :-
// Block : {
βLabelβ : {
βValuesβ : { β β
}
}
}
Variables, Functions & Dynamic Config
Variables : Variables let you reuse values instead of repeating them.
Functions : Little tools that do a job . Terraform has built-in functions that help you do things like Combine text, Get the Length of a list, Format strings, Convert values.
Dynamic Config : Sometimes you want to create a resource multiple times, or only if needed. That time we use Dynamic Config.
Basic Syntax :
variable "region" {
type = string
description = "please decleard EC2 region"
}
variable "ami" {
type = string
description = "Please enter the ami number "
}
variable "instance_type" {
type = string
description = "Please enter the instance type"
}
provider "aws" {
region = var.region
}
resource "aws_vpc" "Terraform-vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "ec2-vpc" }
}
resource "aws_subnet" "Terraform-vpc" {
vpc_id = aws_vpc.Terraform-vpc.id
cidr_block = "10.0.0.0/24"
availability_zone = "default"
tags = {
Name = "ec2-subnet" }
}
resource "aws_security_group" "sg" {
name = ""
description = ""
ingress {
from_port = 22
to_port = 22
protocol = ""
}
ingress {
from_port = 8080
to_port = 8080
protocol = ""
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
}
}
resource "aws_instance" "FirstInstance" {
ami = var.ami
instance_type = var.instance_type
}


Day 3 was about exploring a few more powerful features of Terraform.
πΈ Output Values
I learned how to use output variables to print important information after the infrastructure is created β like instance IP, repository URL, etc. This is very useful in real-world projects.
πΈ Formatting and Console
terraform fmt β Automatically formats the code (like Prettier for Terraform )
terraform console β A handy tool to test expressions, lookups, and see how variables behave
These might look small, but they help a lot with debugging and writing clean code.
These first 3 days with Terraform have been super exciting. I love how simple, powerful, and cloud-agnostic it is. The hands-on practice helped me build confidence, and Iβm looking forward to learning terrafrom.
Thanks for reading! If you're also learning Terraform or just starting your DevOps journey, feel free to connect β Iβd love to learn and grow together. π
