diff --git a/deployment-size.tf b/deployment-size.tf new file mode 100644 index 000000000..9303a28fb --- /dev/null +++ b/deployment-size.tf @@ -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" + } + } +} \ No newline at end of file diff --git a/examples/byo-vpc-eks/main.tf b/examples/byo-vpc-eks/main.tf index d2b29b0ea..d31013c9f 100644 --- a/examples/byo-vpc-eks/main.tf +++ b/examples/byo-vpc-eks/main.tf @@ -22,8 +22,8 @@ provider "aws" { default_tags { tags = { - GithubRepo = "terraform-aws-wandb" - GithubOrg = "wandb" + GithubRepo = "terraform-aws-wandb" + GithubOrg = "wandb" Environment = "Production" } } @@ -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 diff --git a/examples/byo-vpc-eks/variables.tf b/examples/byo-vpc-eks/variables.tf index 0f6d617cf..1ab09894d 100644 --- a/examples/byo-vpc-eks/variables.tf +++ b/examples/byo-vpc-eks/variables.tf @@ -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" } diff --git a/examples/public-dns-external/main.tf b/examples/public-dns-external/main.tf index e7965f1f0..ab506adae 100644 --- a/examples/public-dns-external/main.tf +++ b/examples/public-dns-external/main.tf @@ -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" { @@ -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 +} \ No newline at end of file diff --git a/examples/public-dns-external/variables.tf b/examples/public-dns-external/variables.tf index e0712159b..040018864 100644 --- a/examples/public-dns-external/variables.tf +++ b/examples/public-dns-external/variables.tf @@ -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 diff --git a/main.tf b/main.tf index e97309906..14bafe24e 100644 --- a/main.tf +++ b/main.tf @@ -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 @@ -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 @@ -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 { @@ -285,3 +285,4 @@ module "wandb" { } } } + diff --git a/modules/app_eks/variables.tf b/modules/app_eks/variables.tf index 6f0f58983..25d466197 100644 --- a/modules/app_eks/variables.tf +++ b/modules/app_eks/variables.tf @@ -115,3 +115,9 @@ variable "service_port" { type = number default = 32543 } + +variable "desired_capacity" { + description = "Desired number of worker nodes." + type = number + default = 2 +} diff --git a/outputs.tf b/outputs.tf index 43e880484..4813e691c 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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." @@ -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" diff --git a/variables.tf b/variables.tf index c3565462b..407a76015 100644 --- a/variables.tf +++ b/variables.tf @@ -17,6 +17,13 @@ variable "use_internal_queue" { default = false } +variable "size" { + default = "small" + description = "Deployment size" + nullable = true + type = string +} + ########################################## # Database # ########################################## @@ -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"