Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 

Repository files navigation

Terraform AWS Infrastructure Demo

A demonstration of Infrastructure as Code (IaC) using Terraform to provision and manage AWS cloud resources efficiently and consistently.

πŸ“‹ Overview

This project showcases best practices for managing AWS infrastructure using Terraform. It includes VPC setup, EKS cluster provisioning, RDS database, S3 storage, and comprehensive security configurations.

πŸ› οΈ Technologies Used

  • Infrastructure as Code: Terraform
  • Cloud Provider: AWS
  • Container Orchestration: Amazon EKS
  • Database: Amazon RDS (PostgreSQL)
  • Storage: Amazon S3
  • Monitoring: CloudWatch

πŸ“‚ Project Structure

terraform-aws-infra-demo/
β”œβ”€β”€ main.tf                 # Main Terraform configuration
β”œβ”€β”€ variables.tf            # Input variables definition
β”œβ”€β”€ outputs.tf              # Output values
β”œβ”€β”€ terraform.tfvars.example # Environment variables template
β”œβ”€β”€ modules/                # Reusable Terraform modules
β”‚   β”œβ”€β”€ vpc/
β”‚   β”œβ”€β”€ eks/
β”‚   β”œβ”€β”€ rds/
β”‚   └── s3/
β”œβ”€β”€ environments/           # Environment-specific configs
β”‚   β”œβ”€β”€ dev/
β”‚   β”œβ”€β”€ staging/
β”‚   └── prod/
└── README.md

☁️ Infrastructure Components

Network Layer

  • VPC: Custom VPC with public/private subnets
  • Internet Gateway: Public internet access
  • NAT Gateway: Outbound internet for private subnets
  • Route Tables: Proper routing configuration
  • Security Groups: Controlled access rules

Compute Layer

  • EKS Cluster: Managed Kubernetes cluster
  • Worker Nodes: Auto-scaling node groups
  • Load Balancer: Application Load Balancer (ALB)
  • Auto Scaling: Dynamic scaling based on demand

Database Layer

  • RDS PostgreSQL: Managed database service
  • Multi-AZ: High availability setup
  • Backup: Automated backup configuration
  • Encryption: Data encryption at rest and in transit

Storage Layer

  • S3 Buckets: Object storage with versioning
  • Lifecycle Policies: Cost optimization
  • Encryption: Server-side encryption
  • Access Logging: Audit trail

πŸš€ Quick Start

Prerequisites

# Install Terraform
brew install terraform

# Install AWS CLI
brew install awscli

# Configure AWS credentials
aws configure

Deployment Steps

  1. Clone the repository:

    git clone https://github.com/hamelin123/terraform-aws-infra-demo.git
    cd terraform-aws-infra-demo
  2. Initialize Terraform:

    terraform init
  3. Plan the deployment:

    terraform plan -var-file="environments/dev/terraform.tfvars"
  4. Apply the configuration:

    terraform apply -var-file="environments/dev/terraform.tfvars"
  5. Verify deployment:

    terraform output

βš™οΈ Configuration

Environment Variables

# terraform.tfvars example
aws_region = "ap-southeast-1"
environment = "dev"
project_name = "demo-infra"

# VPC Configuration
vpc_cidr = "10.0.0.0/16"
availability_zones = ["ap-southeast-1a", "ap-southeast-1b"]

# EKS Configuration
kubernetes_version = "1.28"
node_instance_type = "t3.medium"
node_min_size = 1
node_max_size = 3

# RDS Configuration
db_instance_class = "db.t3.micro"
db_name = "demo_db"
db_username = "admin"

Module Usage

# Example module usage
module "vpc" {
  source = "./modules/vpc"
  
  vpc_cidr           = var.vpc_cidr
  availability_zones = var.availability_zones
  environment        = var.environment
}

module "eks" {
  source = "./modules/eks"
  
  cluster_name    = "${var.project_name}-${var.environment}"
  vpc_id          = module.vpc.vpc_id
  subnet_ids      = module.vpc.private_subnet_ids
  node_groups     = var.node_groups
}

πŸ“Š Infrastructure Metrics

Cost Estimation (Monthly)

  • VPC + NAT Gateway: ~$45
  • EKS Cluster: ~$73
  • RDS (t3.micro): ~$15
  • S3 Storage (100GB): ~$2.3
  • Total Estimated: ~$135/month

Performance Specs

  • EKS Nodes: 1-3 t3.medium instances
  • Database: PostgreSQL 14, 20GB storage
  • Network: Multi-AZ deployment
  • Monitoring: CloudWatch integration

πŸ”’ Security Features

Network Security

  • Private Subnets: Database and worker nodes isolation
  • Security Groups: Least privilege access
  • NACLs: Additional network layer protection
  • VPN Gateway: Secure remote access (optional)

Data Security

  • Encryption: All data encrypted at rest and in transit
  • KMS: AWS Key Management Service integration
  • IAM Roles: Fine-grained permissions
  • S3 Bucket Policies: Secure object access

Compliance

  • AWS Config: Resource compliance monitoring
  • CloudTrail: API call logging
  • GuardDuty: Threat detection (optional)
  • Backup: Automated backup strategies

🎯 Key Features

  • Multi-Environment: Dev, Staging, Production ready
  • Modular Design: Reusable infrastructure components
  • Auto Scaling: Dynamic resource scaling
  • High Availability: Multi-AZ deployment
  • Cost Optimized: Right-sized resources
  • Monitoring Ready: CloudWatch integration

πŸ“ˆ Terraform State Management

Backend Configuration

terraform {
  backend "s3" {
    bucket         = "terraform-state-demo-bucket"
    key            = "dev/terraform.tfstate"
    region         = "ap-southeast-1"
    encrypt        = true
    dynamodb_table = "terraform-state-lock"
  }
}

State Management Best Practices

  • Remote State: S3 backend with DynamoDB locking
  • Workspace: Environment isolation
  • Versioning: State file versioning enabled
  • Encryption: State encryption at rest

πŸ› οΈ Maintenance Commands

# Format Terraform files
terraform fmt -recursive

# Validate configuration
terraform validate

# Show current state
terraform show

# Import existing resources
terraform import aws_instance.example i-1234567890abcdef0

# Destroy infrastructure
terraform destroy -var-file="environments/dev/terraform.tfvars"

πŸ“š Documentation


🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Test with terraform plan
  4. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ—οΈ Infrastructure as Code Made Simple

Built with πŸ’™ for Cloud Engineers

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors