Infrastructure Architecture

Terraform architecture model for MILU2 Stage Infrastructure

Shared vs Stage

Terraform is split into 2 separate configs, each with its own state file:

SharedStage
ScopeGlobal / account-levelPer-region
ResourcesS3 (4 bucket), IAM role, CloudFront (2)VPC, Subnets, ALB, NLB, EC2, ECR, ACM, Route53, CloudWatch
State fileshared/terraform.tfstateterraform.tfstate
Existing mechanismYes — auto skip if existsAuto-import 31 resource types

Info

Operational flow: (1) shared runs first (once) — creates global resources. (2) stage runs after (once per region/stage_index).

Network Topology

Overview diagram of network components and traffic flow:

Architecture Overview Diagram
Network Topology (ASCII)
Internet
                        │
              ┌─────────┴─────────┐
              │ ALB internet-facing│ (443 HTTPS)
              └─────────┬─────────┘
                        │
   ┌────────────────────┴─────────────────────────┐
   │  milu2stage-vpc  (172.{34+stage_index}.0.0/16)│
   │  ┌──────────────┐       ┌──────────────┐     │
   │  │ subnet main  │       │ subnet second│     │
   │  │   (AZ-1)     │       │   (AZ-2)     │     │
   │  └──────┬───────┘       └──────┬───────┘     │
   │         │  ALB internal / NLB  │             │
   │         │   ASG(API)  EC2(Web/DB/Node)       │
   └─────────┼──────────────────────┼─────────────┘
             │  VPC Peering (pcx)   │
             ▼                      ▼
       milu2-vpc (build, 172.31.0.0/16) — cùng account

CIDR Scheme

All CIDRs (VPC + subnets) are computed automatically from stage_index variable:

stage_indexVPC CIDRSubnet mainSubnet second
0172.34.0.0/16172.34.0.0/24172.34.1.0/24
1172.35.0.0/16172.35.0.0/24172.35.1.0/24
2172.36.0.0/16172.36.0.0/24172.36.1.0/24
............

Tip

reserved_offsets automatically skips used CIDRs (172.30–33.0.0/16). preflight-check.ps1 suggests available stage_index when VPC Peering is enabled.

VPC Peering

Enables communication between stage VPC and build VPC:

VPC Peering Configuration
# terraform.tfvars
peer_build_vpc_id   = "vpc-xxxxxxxxx"      # VPC ID of the build VPC
peer_build_vpc_cidr = "172.31.0.0/16"      # CIDR of the build VPC
peer_region         = "ap-northeast-1"     # Region (leave empty if same region)

Security Groups

7 Security Groups by role:

NamePurpose
milu2stage-VN-trusted-ip-sgOffice / trusted IPs
MILU2stage-sgGeneral app SG
MILU2-stage-node-game-sgNode game
MILU2-stage-node-world-sgNode world
MILU2-stage-node-chat-sgNode chat
MILU2-stage-node-commu-sgNode commu
milu2stage-dbDB / ICMP