17-EC2 Instances
Module tạo fixed EC2 instances cho 12 roles khác nhau
Stage Modulemodules/17-ec2-instances
Roles
| Role | Mô tả | Default Count |
|---|---|---|
| web | Web frontend | 1 |
| webphp | Web PHP | 1 |
| push | Push notification | 1 |
| mongo | MongoDB | 1 |
| mysql | MySQL primary | 1 |
| mysql_mirror | MySQL mirror/slave | 1 |
| redis | Redis cache | 1 |
| node_center | Node center | 1 |
| node_game | Node game | 1 |
| node_world | Node world | 1 |
| node_chat | Node chat | 1 |
| node_commu | Node community | 1 |
Configuration
EC2 Configuration
# terraform.tfvars
# Enable/disable this module
create_instances = true # false = infra only, no EC2
# Scale instances per role
instance_counts = {
web = 2 # Scale web to 2
node_commu = 3 # Scale node_commu to 3
node_world = 2
# Omit key = default 1
# Set 0 = skip role
}
# DB AMI override (pre-baked snapshots)
ec2_ami_ids_db = {
mysql = "ami-prebaked-mysql"
mysql_mirror = "ami-prebaked-mysql"
}
# Second EBS for mysql/mysql_mirror
ebs_home2_size_gb = 100 # Set 0 to disableNguy hiểm
user_data_replace_on_change = true: Thay đổi scripts/*.sh sẽ DESTROY + CREATE lại EC2. Backup dữ liệu trước!
Target Apply
Target Apply
# Replace specific instance
terraform apply -replace='module.ec2_instances.aws_instance.this["mysql-1"]'
# Replace multiple instances
terraform apply \
-replace='module.ec2_instances.aws_instance.this["mysql-1"]' \
-replace='module.ec2_instances.aws_instance.this["mysql_mirror-1"]'Outputs
| Tên | Mô tả |
|---|---|
| instance_ids | Map role → instance IDs |
| private_ips | Map role → private IPs |