Terraform Infra

Overview
This project provisions AWS infrastructure using Terraform, enabling a consistent and repeatable setup for compute, networking, and container registry.
The goal is to define infrastructure as code so environments can be created, updated, and managed without manual configuration.
Stack
Terraform
Amazon EC2
Amazon VPC
Amazon ECR
AWS Security Groups
Architecture
VPC → Subnet → Internet Gateway → EC2 → Security Group → ECRTerraform Configuration
Provider
provider "aws" {
region = "ap-south-1"
}VPC
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
}Subnet
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
}Internet Gateway
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.main.id
}Security Group
resource "aws_security_group" "web" {
vpc_id = aws_vpc.main.id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}EC2 Instance
resource "aws_instance" "app" {
ami = "ami-0abcdef12345"
instance_type = "t2.micro"
subnet_id = aws_subnet.public.id
vpc_security_group_ids = [aws_security_group.web.id]
tags = {
Name = "devops-app"
}
}ECR Repository
resource "aws_ecr_repository" "repo" {
name = "app-repo"
}Commands
terraform init
terraform plan
terraform applyResult
Infrastructure created using code
EC2 instance ready for deployment
Secure networking with VPC and Security Groups
Container registry available in ECR
Key Points
Infrastructure is version-controlled
Same setup across environments
No manual AWS configuration
Easy to scale and modify
Final Note
This setup demonstrates how infrastructure can be managed as code.
It ensures environments are consistent, repeatable, and easy to maintain in production systems.

