🚀 Terraform with AWS – Day 02: Providers, Resources & Variables

Abdul RaheemAbdul Raheem
2 min read

Yesterday, I kicked off my Terraform journey by installing it and launching my very first EC2 instance.
👉 Today, I went deeper and explored Providers, Resources, and Variables in Terraform.

By the end of the day, I had provisioned both an EC2 instance and an S3 bucket using clean and reusable code. Let’s walk through it!


🔹 What are Providers?

A provider allows Terraform to talk to a specific platform (like AWS, GCP, or Azure).
Since I’m working with AWS, I used the AWS provider:

provider "aws" {
  region = var.region
}

This tells Terraform to work with AWS in the specified region.


🔹 What are Resources?

A resource defines something we want Terraform to create or manage.
Examples:

  • EC2 instance

  • S3 bucket

  • IAM user

Here’s an EC2 instance resource:

resource "aws_instance" "example" {
  ami           = "ami-08c40ec9ead489470"
  instance_type = var.instance_type

  tags = {
    Name = "Terraform-Instance-Variables"
  }
}

And here’s an S3 bucket resource:

resource "aws_s3_bucket" "my_bucket" {
  bucket = "abdul-terraform-bucket-12345"
  acl    = "private"
}

🔹 Why Use Variables?

Instead of hardcoding values, Terraform lets us define variables for flexibility.

variable "region" {
  default = "us-east-1"
}

variable "instance_type" {
  default = "t2.micro"
}

👉 Now, I can change regions or instance types without touching the main code.


▶️ Terraform Commands I Used

Here are the 5 essential commands I practiced today:

1️⃣ terraform init

Initializes the project and downloads required providers.

terraform init

2️⃣ terraform validate

Checks if the code is syntactically valid.

terraform validate

3️⃣ terraform plan

Previews what Terraform will do before making changes.

terraform plan

4️⃣ terraform apply

Applies the configuration and creates infrastructure.

terraform apply

5️⃣ terraform destroy

Destroys all resources when no longer needed.

terraform destroy

💡 Key Takeaways from Day 02

✅ Providers connect Terraform with cloud platforms like AWS.
✅ Resources define the infrastructure we want to manage.
✅ Variables make code flexible & reusable.
✅ Learned 5 core commands: init, validate, plan, apply, destroy.


🔗 Follow My Journey


✨ That’s the end of Day 02. Tomorrow, I’ll dive deeper into Terraform state management and best practices. Stay tuned!

0
Subscribe to my newsletter

Read articles from Abdul Raheem directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abdul Raheem
Abdul Raheem

Cloud DevOps | AWS | Terraform | CI/CD | Obsessed with clean infrastructure. Cloud DevOps Engineer 🚀 | Automating Infrastructure & Securing Pipelines | Bridging Gaps Between Code and Cloud ☁️ I’m on a mission to master DevOps from the ground up—building scalable systems, automating workflows, and integrating security into every phase of the SDLC. Currently working with AWS, Terraform, Docker, CI/CD, and learning the art of cloud-native development.