This repository contains a fully automated, production-ready AWS infrastructure built using Terraform. It includes VPC networking, subnets, NAT gateways, bastion host, application servers, Network Load Balancer (NLB), Route53 DNS, ACM TLS certificates, RDS MySQL, Auto Scaling Group (ASG), S3 static hosting, CloudFront CDN, CloudWatch monitoring and more.
The Terraform code provisions:
- 1 VPC (10.10.0.0/16)
- Public subnets (2개 AZ: ap-northeast-2b, 2c)
- Private subnet (1개 AZ)
- Internet Gateway
- NAT Gateway with Elastic IP
- Route tables and routing configuration
- Security groups for public, private, database layers
- Network ACLs for additional security
- Bastion host (public subnet) - Ubuntu
- AWS Linux Server (private subnet)
- RedHat Server (private subnet)
- Auto Scaling Group (private subnet)
- Launch Template based instances
- Min 1, Max 3
- CPU-based scale-in/scale-out
- Network Load Balancer (NLB)
- Listener ports: 80/TCP, 443/TLS, 8080/TCP
- Target Group automatically populated by ASG instances
- Hosted Zone via Route53 (insung-terraform.com)
- ALIAS record (api.insung-terraform.com) → NLB
- ACM certificate with DNS validation
- TLS termination on NLB (port 443)
- RDS MySQL 8.0 (db.t3.micro)
- 8GB allocated storage
- Automatic backup enabled (7 days retention)
- Backup window: 03:00-04:00 UTC
- ElastiCache Redis 7.1 (cache.t3.micro)
- Single node cluster
- Port 6379
- Deployed in VPC subnet group
- S3 Bucket (private, CloudFront OAC access only)
- CloudFront CDN with Origin Access Control
- Price Class: PriceClass_200 (North America, Europe, Asia)
- CloudWatch Log Group (14 days retention)
- CPU High/Low Alarms for Auto Scaling
Internet
│
Route53 (api.insung-terraform.com)
│
ACM (TLS Certificate)
│
Network Load Balancer (80 / 443 / 8080)
│
┌────────────────────────────────────────────┐
│ AWS VPC │
│ (10.10.0.0/16) │
│ ┌───────────────────────────┐ │
│ │ Public Subnets │ │
│ │ - Bastion Host │ │
│ │ - NAT Gateway │ │
│ │ - NLB │ │
│ └───────────────────────────┘ │
│ ┌───────────────────────────┐ │
│ │ Private Subnets │ │
│ │ - ASG Auto EC2 (1~3) │ │
│ │ - AWS Linux Server │ │
│ │ - RedHat Server │ │
│ └───────────────────────────┘ │
│ ┌───────────────────────────┐ │
│ │ Database & Cache │ │
│ │ - RDS MySQL 8.0 │ │
│ │ - ElastiCache Redis 7.1 │ │
│ └───────────────────────────┘ │
└────────────────────────────────────────────┘
CloudFront CDN ──► S3 Bucket (Static Content)
AWS-terraform/
├── aws-provider.tf # AWS provider configuration
├── vpc.tf # VPC configuration
├── public_subnet-gateway.tf # Public subnets & Internet Gateway
├── private_subnet-gateway.tf# Private subnets & NAT Gateway
├── security_group.tf # Security groups
├── security_group_ACL.tf # Network ACLs
├── instance.tf # EC2 instances (Bastion, Linux, RedHat)
├── launch_template.tf # Launch template for ASG
├── autoscaling.tf # Auto Scaling Group & policies
├── nlb.tf # Network Load Balancer
├── route53.tf # Route53 DNS configuration
├── acm.tf # ACM TLS certificate
├── database.tf # RDS MySQL database
├── redis.tf # ElastiCache Redis cluster
├── s3.tf # S3 bucket for static content
├── cloudfront.tf # CloudFront CDN distribution
└── cloudwatch.tf # CloudWatch logs & alarms
| Condition | Action |
|---|---|
| CPU ≥ 40% | Scale-Out (+1 instance) |
| CPU ≤ 20% | Scale-In (–1 instance) |
| Min Size | Always 1 |
| Max Size | Up to 3 |
| Cooldown | 60 seconds |
| Setting | Value |
|---|---|
| Retention Period | 7 days |
| Backup Window | 03:00-04:00 UTC |
| Delete on Termination | No (backups preserved) |
| Setting | Value |
|---|---|
| Engine | Redis 7.1 |
| Node Type | cache.t3.micro |
| Number of Nodes | 1 |
| Port | 6379 |
| Parameter Group | default.redis7 |
- Public: Web traffic (HTTP/HTTPS)
- Private: Internal application traffic
- Database: Restricted access (specific IP only)
- Public ACL: Allow 80, 443, 22, ephemeral ports
- Private ACL: VPC internal + NAT response traffic
- Terraform 1.6+
- AWS Account
- AWS CLI installed (
aws configure) - SSH keypair named
terraform_key - Route53 domain access
terraform init
terraform plan
terraform apply
terraform destroy
ssh -i terraform_key.pem ubuntu@<bastion_public_ip>
ssh ec2-user@<private_ec2_ip>
http://api.insung-terraform.com
https://api.insung-terraform.com
- ElastiCache Redis Cluster Mode for high availability
- Multi-VPC + Transit Gateway
- WAF integration
- ECS Fargate or EKS migration
- Centralized logging (OpenSearch)
- Terraform backend (S3 + DynamoDB)
- GitHub Actions CI/CD
- AWS Secrets Manager for credentials
- VPC Endpoints for cost optimization