Skip to content

Commit c4aed71

Browse files
authored
Merge pull request #198 from willroberts/replace-ecs-ami
Reduces ECS-EC2 root volume size to 8GB in staging
2 parents 4de38e5 + f29378a commit c4aed71

4 files changed

Lines changed: 84 additions & 5 deletions

File tree

terraform/modules/ecs_cluster/ec2.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ locals {
1616

1717
resource "aws_launch_template" "template" {
1818
name_prefix = "ecs-${var.name}"
19-
image_id = local.ami_ids[var.architecture][data.aws_region.current.name]
19+
image_id = var.use_custom_ami ? var.custom_ami_id : local.ami_ids[var.architecture][data.aws_region.current.name]
2020
instance_type = var.instance_type
2121
key_name = aws_key_pair.ssh_key.id
2222
vpc_security_group_ids = var.security_group_ids
@@ -35,7 +35,7 @@ resource "aws_launch_template" "template" {
3535
# Given that we hardly use disks, gp3 should result in a 20% cost reduction.
3636
# If we ever exceed the baseline for IOPS or Throughput, let's go back to gp2.
3737
volume_type = "gp3"
38-
volume_size = 30 # Default is 30GB; we only use 3GB. Need to build our own AMI to reduce this.
38+
volume_size = var.root_volume_size
3939
iops = 3000 # Cap IOPS at 3,000 to avoid overage charges.
4040
throughput = 125 # Cap Throughput at 125MB/s to avoid overage charges.
4141
delete_on_termination = true

terraform/modules/ecs_cluster/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,30 @@ variable "architecture" {
1818
default = "arm64"
1919
}
2020

21+
variable "use_custom_ami" {
22+
type = bool
23+
description = "Set this to true to provide your own AMI ID as var.custom_ami_id."
24+
default = false
25+
}
26+
27+
variable "custom_ami_id" {
28+
type = string
29+
description = "The custom AMI ID to use. Will default to ECS-optimized AMIs if not provided."
30+
default = ""
31+
}
32+
2133
variable "instance_type" {
2234
type = string
2335
description = "The instance type to use for ECS-EC2 instances."
2436
default = "t4g.micro"
2537
}
2638

39+
variable "root_volume_size" {
40+
type = number
41+
description = "The size of the EBS root block device on ECS-EC2 instances."
42+
default = 30
43+
}
44+
2745
variable "min_capacity" {
2846
type = number
2947
description = "The minimum number of ECS-EC2 instances."

terraform/staging/ecs.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
module "ecs_cluster" {
2-
source = "../modules/ecs_cluster"
3-
name = "duelyst-staging"
4-
ssh_public_key = var.ssh_public_key
2+
source = "../modules/ecs_cluster"
3+
name = "duelyst-staging"
4+
use_custom_ami = true
5+
custom_ami_id = var.custom_ami_id
6+
root_volume_size = 8
7+
ssh_public_key = var.ssh_public_key
58

69
# Set capacity to 3 to allow graceful deployments without stopping live containers.
710
min_capacity = 0

terraform/staging/variables.tf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,123 @@
11
# Provide these variables in a terraform.tfvars file.
22

3+
# The AWS region determines where your resources will be created.
4+
# There is a list of available regions here:
5+
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions
36
variable "aws_region" {
47
type = string
58
}
69

10+
# By default, we use Amazon's ECS-Optimized AMI.
11+
# You may want to use a custom image for a variety of reasons, such as reducing
12+
# the default disk size of 30GB.
13+
# To create custom AMIs, use Amazon's open source tool here:
14+
# https://github.com/aws/amazon-ecs-ami/
15+
variable "custom_ami_id" {
16+
type = string
17+
default = ""
18+
}
19+
20+
# The AWS Access Key ID for your Terraform IAM user.
21+
# This is only used in the provider configuration, and will not be stored in
22+
# the Terraform state.
723
variable "aws_access_key" {
824
type = string
925
}
1026

27+
# The AWS Secret Access Key for your Terraform IAM user.
28+
# This is only used in the provider configuration, and will not be stored in
29+
# the Terraform state.
1130
variable "aws_secret_key" {
1231
type = string
1332
}
1433

34+
# The SSH public key to attach to your ECS-EC2 instances.
1535
variable "ssh_public_key" {
1636
type = string
1737
}
1838

39+
# The S3 bucket name for storing Duelyst static assets.
40+
# This name must be globally unique across all of AWS.
1941
variable "assets_bucket_name" {
2042
type = string
2143
}
2244

45+
# The S3 bucket name for storing Duelyst game replays.
46+
# This name must be globally unique across all of AWS.
2347
variable "replays_bucket_name" {
2448
type = string
2549
}
2650

51+
# The domain name for the staging API service, e.g. play.duelyst.com.
2752
variable "staging_domain_name" {
2853
type = string
2954
}
3055

56+
# The domain name for the CDN, e.g. cdn.duelyst.com.
3157
variable "cdn_domain_name" {
3258
type = string
3359
}
3460

61+
# The first of three availability zones to use when creating AWS resources.
62+
# You can find a list of Availability Zones you can use by following these
63+
# instructions:
64+
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#availability-zones-describe
65+
# Note that availability zones are randomized for each AWS account. In other
66+
# words, us-east-1a in one account may not be the same datacenter as us-east-1a
67+
# in another AWS account.
3568
variable "first_availability_zone" {
3669
type = string
3770
}
3871

72+
# The second of three availability zones to use when creating AWS resources.
73+
# You can find a list of Availability Zones you can use by following these
74+
# instructions:
75+
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#availability-zones-describe
76+
# Note that availability zones are randomized for each AWS account. In other
77+
# words, us-east-1a in one account may not be the same datacenter as us-east-1a
78+
# in another AWS account.
3979
variable "second_availability_zone" {
4080
type = string
4181
}
4282

83+
# The third of three availability zones to use when creating AWS resources.
84+
# You can find a list of Availability Zones you can use by following these
85+
# instructions:
86+
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#availability-zones-describe
87+
# Note that availability zones are randomized for each AWS account. In other
88+
# words, us-east-1a in one account may not be the same datacenter as us-east-1a
89+
# in another AWS account.
4390
variable "third_availability_zone" {
4491
type = string
4592
}
4693

94+
# The name of your Firebase project.
95+
# This is not the URL, but the shorthand project name e.g. "duelyst-12345".
96+
# This is used for Firebase authentication flows in the backend services.
4797
variable "firebase_project" {
4898
type = string
4999
}
50100

101+
# The URL of your Firebase Realtime Database.
102+
# This must end in ".firebaseio.com/", including the trailing slash.
51103
variable "firebase_url" {
52104
type = string
53105
}
54106

107+
# The name of the user to create in the RDS Postgres database instance.
108+
# This should match the username used in the "postgres_connection_string"
109+
# config value in the app.
55110
variable "database_user" {
56111
type = string
57112
}
58113

114+
# The 8-character, alphanumeric ID for your public ECR registry.
115+
# This is used to tell ECS services where to obtain container images.
59116
variable "ecr_registry_id" {
60117
type = string
61118
}
62119

120+
# Cloudwatch Alarms will be routed to this email address.
63121
variable "email_address_for_alarms" {
64122
type = string
65123
}

0 commit comments

Comments
 (0)