Skip to content

Latest commit

 

History

History
131 lines (74 loc) · 3.52 KB

README.md

File metadata and controls

131 lines (74 loc) · 3.52 KB

Microservices with ALB - Terraform Infrastructure

Overview

This repository provides a Terraform-based infrastructure-as-code (IaC) solution to deploy a microservices architecture using AWS services. The architecture includes:

Application Load Balancer (ALB) with Path-Based Routing

EC2 Auto-Scaling Groups for scalable compute resources

AWS Lambda for serverless compute needs

Amazon Aurora and DynamoDB databases for storage

High availability and multi-AZ support

Secure VPC setup with public and private subnets

Multiple environments (Production, Development, QA, Staging)

Architecture Diagram

Components

VPC: Secure network with public and private subnets.

ALB: Manages traffic routing based on paths to different services.

Target Groups: Routes traffic to EC2 instances, Lambda, and Kubernetes.

Auto Scaling Groups: Ensures high availability and scalability for EC2.

Lambda: Serverless computing for microservices.

Aurora and DynamoDB: Databases for different services.

Security Groups: Provides firewall-level security.

Directory Structure

├── terraform/ │ ├── providers.tf # AWS provider configuration │ ├── vpc.tf # VPC and subnet definitions │ ├── security_groups.tf # Security group definitions │ ├── alb.tf # Application Load Balancer configuration │ ├── target_groups.tf # Target groups and rules for ALB │ ├── listeners.tf # Listener rules for ALB │ ├── autoscaling.tf # EC2 auto-scaling group setup │ ├── lambda.tf # AWS Lambda configuration │ ├── iam.tf # IAM roles and policies │ ├── databases.tf # Aurora and DynamoDB configuration │ ├── variables.tf # Input variables │ ├── outputs.tf # Outputs of the infrastructure │ ├── terraform.tfvars # Environment-specific variables │ ├── backend.tf # Remote backend configuration │ ├── versions.tf # Version constraints └── README.md

Prerequisites

Terraform: Install Terraform CLI from Terraform Download.

AWS CLI: Install AWS CLI and configure credentials.

IAM Role: Ensure you have permissions to create IAM roles, VPCs, EC2 instances, and RDS databases.

Terraform Backend: Setup S3 bucket and DynamoDB for remote state management.

Environments

The infrastructure is designed to support multiple environments:

Production

Development

QA

Staging

Use terraform.tfvars to define variables specific to each environment.

Deployment Steps

Clone Repository

git clone https://github.com/yourusername/repository-name.git cd repository-name/terraform

Initialize Terraform

terraform init

Plan Changes

terraform plan -var-file="terraform.tfvars"

Apply Changes

terraform apply -var-file="terraform.tfvars"

Destroy Infrastructure (if required)

terraform destroy -var-file="terraform.tfvars"

Outputs

After successful deployment, the ALB DNS name will be provided as output:

Outputs: alb_dns_name = "example-alb-12345678.us-east-1.elb.amazonaws.com"

Security Measures

Security groups enforce least privilege principles.

Database credentials are managed securely using environment variables.

Data in transit is secured using HTTPS.

Multi-AZ deployments ensure high availability and disaster recovery.

Access control policies implemented for IAM roles.

Monitoring & Logging

AWS CloudWatch is used for monitoring logs and performance metrics.

Alarms can be configured to notify admins of any failures.