This directory contains a modular Terraform structure designed for the Internal Developer Platform. Each AWS service is separated into its own reusable module, and application templates combine these modules to create complete solutions.
terraform/
├── modules/ # Reusable service modules
│ ├── aws-ec2/ # EC2 instances
│ ├── aws-s3/ # S3 buckets
│ ├── aws-rds/ # RDS databases
│ ├── aws-cloudfront/ # CloudFront distributions
│ └── aws-security-group/ # Security groups
├── templates/ # Application templates
│ ├── web-app-simple/ # Simple web application
│ ├── api-simple/ # Simple API service
│ └── sirwan-test/ # Advanced S3 bucket template
└── environments/ # Environment-specific configurations
├── dev/
├── staging/
└── prod/
- Purpose: Creates EC2 instances with configurable settings
- Features:
- Multiple instance types
- Custom user data scripts
- Security group configuration
- EBS volume management
- CloudWatch monitoring
- Elastic IP support
- Purpose: Creates S3 buckets for various use cases
- Features:
- Static website hosting
- Versioning and encryption
- Lifecycle policies
- CORS configuration
- Public/private access control
- Purpose: Creates managed database instances
- Features:
- Multiple database engines (PostgreSQL, MySQL)
- Backup and recovery
- Performance monitoring
- Security group integration
- Multi-AZ deployment
Combines multiple services for a complete web application:
- Frontend: S3 bucket with static website hosting
- Backend: EC2 instance for API server (optional)
- Database: RDS instance (optional)
- CDN: CloudFront distribution (optional)
Lightweight API service template:
- Compute: EC2 instance with auto-configuration
- Database: RDS instance (optional)
- Monitoring: CloudWatch integration
Advanced S3 bucket template showcasing modular architecture:
- Primary Storage: S3 bucket with comprehensive configuration
- Backup Storage: Optional secondary bucket with retention policies
- Lifecycle Management: Automatic cost optimization with storage class transitions
- Website Hosting: Optional static website hosting with CORS
- Monitoring: CloudWatch logging and event notifications
- Security: Encryption, versioning, and access controls
# Create an EC2 instance
module "web_server" {
source = "./modules/aws-ec2"
name = "my-web-server"
instance_type = "t2.micro"
environment = "dev"
instance_purpose = "web-server"
tags = {
Project = "MyApp"
}
}
# Create an S3 bucket
module "static_website" {
source = "./modules/aws-s3"
bucket_name = "my-static-site"
website_enabled = true
public_read_access = true
environment = "dev"
}# Deploy a complete web application
module "my_web_app" {
source = "./templates/web-app-simple"
app_name = "my-awesome-app"
environment = "dev"
backend_api = true
database_required = true
database_type = "postgres"
tags = {
Project = "MyApp"
Owner = "DevTeam"
}
}- Reusability: Each service module can be used across different applications
- Maintainability: Changes to a service affect all applications using it
- Consistency: Standardized configurations across all deployments
- Flexibility: Mix and match services as needed
- Testing: Each module can be tested independently
- Cost Control: Each module includes cost optimization features
- Version your modules: Use git tags for module versions
- Document modules: Each module should have comprehensive documentation
- Test modules: Create test cases for each module
- Use consistent naming: Follow naming conventions across all modules
- Tag resources: Apply consistent tagging for cost tracking and management
- Develop services: Create or modify individual service modules
- Test services: Test modules independently
- Compose templates: Combine services into application templates
- Test templates: Validate complete application deployments
- Deploy: Use templates for actual deployments
Each module is designed with AWS Free Tier in mind:
- EC2: Uses t2.micro instances by default
- RDS: Uses t3.micro instances with minimal storage
- S3: Configured for standard storage with lifecycle policies
- Monitoring: Basic CloudWatch metrics included
- Encryption: All storage encrypted by default
- Network Security: Proper security group configurations
- IAM: Least privilege access patterns
- VPC: Secure network configurations
Planned additions:
- AWS Lambda module
- AWS API Gateway module
- AWS CloudWatch module
- AWS ELB module
- Kubernetes deployment templates
- CI/CD pipeline templates