Learning DevOps: Day 10🚀
🚀 Getting Started with Terraform: My First EC2 Instance Deployment
Introduction
As part of my DevOps learning journey, I explored Terraform, a powerful Infrastructure as Code (IaC) tool. In this article, I'll share what Terraform is, why we use it, and walk you through my first Terraform project, where I deployed an EC2 instance on AWS.
🌍 What is Terraform?
Terraform is an open-source IaC tool that allows us to define, provision, and manage cloud resources using a declarative configuration language.
Why Use Terraform?
✅ Automates Infrastructure – No need to create resources manually.
✅ Idempotency – Ensures infrastructure remains consistent.
✅ Multi-Cloud Support – Works with AWS, Azure, GCP, etc.
✅ Version Control – Terraform files can be stored in GitHub, making infrastructure changes trackable.
🔥 My First Terraform Project: Deploying an EC2 Instance
1️⃣ Install Terraform
Before starting, install Terraform by following the official guide: 🔗 Install Terraform
2️⃣ Configure AWS Credentials
Ensure you have AWS credentials set up. Use the AWS CLI to configure them:
aws configure
3️⃣ Write Terraform Configuration
Create a new directory and navigate into it:
create repository in github and use vs code to open that repo
Then, create a main.tf file and add the following Terraform configuration:
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "my_instance" {
ami = "ami-0abcdef1234567890" # Replace with the latest AMI ID
instance_type = "t2.micro"
key_name = "my-key" # Ensure you have this key pair created in AWS
tags = {
Name = "MyTerraformInstance"
}
}
4️⃣ Initialize & Apply Terraform
Run the following Terraform commands:
terraform init
terraform plan
terraform apply
🎉 Hey My EC2 instance is now deployed on AWS! 🚀
📝 My GitHub Repository
I have shared my Terraform project on GitHub. Feel free to check it out
🔮 What's Next?
Now that I have successfully created an EC2 instance using Terraform, my next steps will be:
✅ Automating more AWS resources (VPC, S3, RDS)
✅ Exploring Terraform Modules
✅ Setting up Terraform with CI/CD Pipelines
🎯 Conclusion
Terraform is an essential tool for DevOps professionals, making infrastructure deployment easier, scalable, and version-controlled. This was just my first step in Terraform, and I’m excited to learn more!