Skip to main content

Command Palette

Search for a command to run...

My First 3 Days of Learning Terraform

Updated
β€’4 min read
R

SUCCESS ISN'T OVERNIGHT. IT'S WHEN EVERY DAY YOU GET A LITTLE BETTER THAN THE DAY BEFORE. ITS ALL ADDS UP.

Hey everyone! πŸ‘‹

logo, company name

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

TerraformCloudFormation

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

    1. Variables : Variables let you reuse values instead of repeating them.

    2. 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.

    3. 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. πŸ™Œ