17-EC2 Instances
Module creating fixed EC2 instances for 12 different roles
Stage Modulemodules/17-ec2-instances
Roles
| Role | Description | 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 disableDanger
user_data_replace_on_change = true: Changes to scripts/*.sh will DESTROY + CREATE EC2. Backup data first!
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
| Name | Description |
|---|---|
| instance_ids | Map of role → instance IDs |
| private_ips | Map of role → private IPs |