Skip to content

Commit

Permalink
feat: Add standardized instance sizing in AWS (#172)
Browse files Browse the repository at this point in the history
* Veronica/tshirt deployment (#171)

* feat: Add support for t-shirt-sized deployments

* Remove duplicates

---------

Co-authored-by: Veronica JungYeon Kim <[email protected]>

* changes

* test

* terraform fmt

* touchups

* a bit o polish

---------

Co-authored-by: Veronica JungYeon Kim <[email protected]>
  • Loading branch information
George Scott and kimjyhello authored Feb 8, 2024
1 parent ce44732 commit e6b4ab7
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 44 deletions.
39 changes: 39 additions & 0 deletions deployment-size.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
##################################################
# standard deployment sizes are specified in
# this object
##################################################

locals {
deployment_size = {
small = {
db = "db.r6g.large",
node_count = 2,
node_instance = "r6i.large"
cache = "cache.m6g.large"
},
medium = {
db = "db.r6g.xlarge",
node_count = 2,
node_instance = "r6i.xlarge"
cache = "cache.m6g.large"
},
large = {
db = "db.r6g.2xlarge",
node_count = 2,
node_instance = "r6i.2xlarge"
cache = "cache.m6g.xlarge"
},
xlarge = {
db = "db.r6g.4xlarge",
node_count = 3,
node_instance = "r6i.4xlarge"
cache = "cache.m6g.xlarge"
},
xxlarge = {
db = "db.r6g.8xlarge",
node_count = 3,
node_instance = "r6i.8xlarge"
cache = "cache.m6g.2xlarge"
}
}
}
18 changes: 9 additions & 9 deletions examples/byo-vpc-eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ provider "aws" {

default_tags {
tags = {
GithubRepo = "terraform-aws-wandb"
GithubOrg = "wandb"
GithubRepo = "terraform-aws-wandb"
GithubOrg = "wandb"
Environment = "Production"
}
}
Expand All @@ -38,16 +38,16 @@ module "wandb_infra" {
external_dns = true

create_vpc = false

network_id = var.vpc_id
network_cidr = var.vpc_cidr

network_private_subnets = var.network_private_subnets
network_public_subnets = var.network_public_subnets
network_database_subnets = var.network_database_subnets
network_private_subnet_cidrs = var.network_private_subnet_cidrs
network_public_subnet_cidrs = var.network_public_subnet_cidrs
network_database_subnet_cidrs = var.network_database_subnet_cidrs
network_private_subnets = var.network_private_subnets
network_public_subnets = var.network_public_subnets
network_database_subnets = var.network_database_subnets
network_private_subnet_cidrs = var.network_private_subnet_cidrs
network_public_subnet_cidrs = var.network_public_subnet_cidrs
network_database_subnet_cidrs = var.network_database_subnet_cidrs

deletion_protection = false

Expand Down
54 changes: 27 additions & 27 deletions examples/byo-vpc-eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,45 +85,45 @@ variable "allowed_inbound_ipv6_cidr" {
}

variable "vpc_id" {
type = string
description = "VPC network ID"
type = string
description = "VPC network ID"
}
variable "vpc_cidr" {
type = string
description = "VPC network CIDR"
}
variable vpc_cidr {
type = string
description = "VPC network CIDR"
}

variable network_private_subnets {
type = list[string]
description = "Subnet IDs"
variable "network_private_subnets" {
type = list[string]
description = "Subnet IDs"
}

variable network_public_subnets {
type = list[string]
description = "Subnet IDs"
variable "network_public_subnets" {
type = list[string]
description = "Subnet IDs"
}

variable network_database_subnets {
type = list[string]
description = "Subnet IDs"
variable "network_database_subnets" {
type = list[string]
description = "Subnet IDs"
}

variable network_private_subnet_cidrs {
type = list[string]
description = "Subnet CIDRs"
variable "network_private_subnet_cidrs" {
type = list[string]
description = "Subnet CIDRs"
}

variable network_public_subnet_cidrs {
type = list[string]
description = "Subnet CIDRs"
variable "network_public_subnet_cidrs" {
type = list[string]
description = "Subnet CIDRs"
}

variable network_database_subnet_cidrs {
type = list[string]
description = "Subnet CIDRs"
variable "network_database_subnet_cidrs" {
type = list[string]
description = "Subnet CIDRs"
}

variable eks_cluster_version {
type = string
description = "EKS cluster version"
variable "eks_cluster_version" {
type = string
description = "EKS cluster version"
}
17 changes: 17 additions & 0 deletions examples/public-dns-external/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module "wandb_infra" {
bucket_name = var.bucket_name
bucket_kms_key_arn = var.bucket_kms_key_arn
use_internal_queue = true
size = var.size
}

data "aws_eks_cluster" "app_cluster" {
Expand Down Expand Up @@ -100,3 +101,19 @@ output "bucket_name" {
output "bucket_queue_name" {
value = module.wandb_infra.bucket_queue_name
}

output "database_instance_type" {
value = module.wandb_infra.database_instance_type
}

output "eks_node_instance_type" {
value = module.wandb_infra.eks_node_instance_type
}

output "redis_instance_type" {
value = module.wandb_infra.redis_instance_type
}

output "standardized_size" {
value = var.size
}
7 changes: 7 additions & 0 deletions examples/public-dns-external/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ variable "zone_id" {
description = "Id of Route53 zone"
}

variable "size" {
default = "small"
description = "Deployment size"
nullable = true
type = string
}

variable "subdomain" {
type = string
default = null
Expand Down
17 changes: 9 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module "database" {
database_name = var.database_name
master_username = var.database_master_username

instance_class = var.database_instance_class
instance_class = try(local.deployment_size[var.size].db, var.database_instance_class)
engine_version = var.database_engine_version
snapshot_identifier = var.database_snapshot_identifier
sort_buffer_size = var.database_sort_buffer_size
Expand Down Expand Up @@ -121,10 +121,11 @@ module "app_eks" {
namespace = var.namespace
kms_key_arn = local.kms_key_arn

instance_types = var.kubernetes_instance_types
map_accounts = var.kubernetes_map_accounts
map_roles = var.kubernetes_map_roles
map_users = var.kubernetes_map_users
instance_types = try([local.deployment_size[var.size].node_instance], var.kubernetes_instance_types)
desired_capacity = try(local.deployment_size[var.size].node_count, var.kubernetes_node_count)
map_accounts = var.kubernetes_map_accounts
map_roles = var.kubernetes_map_roles
map_users = var.kubernetes_map_users

bucket_kms_key_arn = local.use_external_bucket ? var.bucket_kms_key_arn : local.kms_key_arn
bucket_arn = data.aws_s3_bucket.file_storage.arn
Expand Down Expand Up @@ -195,9 +196,8 @@ module "redis" {
vpc_id = local.network_id
redis_subnet_group_name = local.network_elasticache_subnet_group_name
vpc_subnets_cidr_blocks = module.networking.elasticache_subnet_cidrs
node_type = var.elasticache_node_type

kms_key_arn = local.kms_key_arn
node_type = try(local.deployment_size[var.size].cache, var.elasticache_node_type)
kms_key_arn = local.kms_key_arn
}

locals {
Expand Down Expand Up @@ -285,3 +285,4 @@ module "wandb" {
}
}
}

6 changes: 6 additions & 0 deletions modules/app_eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,9 @@ variable "service_port" {
type = number
default = 32543
}

variable "desired_capacity" {
description = "Desired number of worker nodes."
type = number
default = 2
}
24 changes: 24 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,27 @@ output "database_password" {
sensitive = true
value = module.database.password
}

output "database_instance_type" {
value = local.deployment_size[var.size].db
}

output "elasticache_connection_string" {
value = var.create_elasticache ? module.redis.0.connection_string : null
}

output "eks_node_count" {
value = local.deployment_size[var.size].node_count
}

output "eks_node_instance_type" {
value = local.deployment_size[var.size].node_instance
}

output "internal_app_port" {
value = local.internal_app_port
}

output "kms_key_arn" {
value = local.kms_key_arn
description = "The Amazon Resource Name of the KMS key used to encrypt data at rest."
Expand All @@ -51,6 +66,15 @@ output "network_public_subnets" {
value = local.network_public_subnets
description = "The identities of the public subnetworks deployed within the VPC."
}

output "redis_instance_type" {
value = local.deployment_size[var.size].cache
}

output "standardized_size" {
value = var.size
}

output "url" {
value = local.url
description = "The URL to the W&B application"
Expand Down
13 changes: 13 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ variable "use_internal_queue" {
default = false
}

variable "size" {
default = "small"
description = "Deployment size"
nullable = true
type = string
}

##########################################
# Database #
##########################################
Expand Down Expand Up @@ -306,6 +313,12 @@ variable "kubernetes_instance_types" {
default = ["m5.large"]
}

variable "kubernetes_node_count" {
description = "Number of nodes"
type = number
default = 2
}

variable "eks_policy_arns" {
type = list(string)
description = "Additional IAM policy to apply to the EKS cluster"
Expand Down

0 comments on commit e6b4ab7

Please sign in to comment.