Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

J7m4/infra 240 aws redis in cluster #330

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/public-dns-external/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ provider "aws" {
}
}


locals {
env_vars = merge(
{
"TAG_CUSTOMER_NS" = var.namespace
"TAG_CLOUD" = "AWS"
},
var.other_wandb_env
)
}


module "wandb_infra" {
source = "../../"

Expand Down Expand Up @@ -38,6 +50,8 @@ module "wandb_infra" {

license = var.wandb_license

other_wandb_env = local.env_vars

bucket_name = var.bucket_name
bucket_path = var.bucket_path
bucket_kms_key_arn = var.bucket_kms_key_arn
Expand All @@ -50,6 +64,14 @@ module "wandb_infra" {
system_reserved_pid = var.system_reserved_pid

aws_loadbalancer_controller_tags = var.aws_loadbalancer_controller_tags

create_elasticache = var.create_elasticache
create_redis_in_cluster = var.create_redis_in_cluster
use_redis_in_cluster = var.use_redis_in_cluster
redis_master_name = var.redis_master_name
redis_service_name_prefix = var.redis_service_name_prefix

kubernetes_alb_internet_facing = var.kubernetes_alb_internet_facing
}

data "aws_eks_cluster" "app_cluster" {
Expand Down
36 changes: 36 additions & 0 deletions examples/public-dns-external/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,39 @@ variable "aws_loadbalancer_controller_tags" {
type = map(string)
default = {}
}

variable "use_redis_in_cluster" {
type = bool
default = false
description = "whether to actually use redis in cluster"
}

variable "create_redis_in_cluster" {
type = bool
default = false
description = "whether to create an in-cluster redis"
}

variable "create_elasticache" {
type = bool
default = true
description = "whether to create an elasticache redis"
}

variable "redis_service_name_prefix" {
type = string
default = null
description = "Prefix of the redis service name"
}

variable "redis_master_name" {
type = string
default = null
description = "Name of the redis master that sentinel uses to monitor"
}

variable "kubernetes_alb_internet_facing" {
type = bool
default = true
description = "Whether to enable private only traffic"
}
26 changes: 21 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ module "app_eks" {
map_roles = var.kubernetes_map_roles
map_users = var.kubernetes_map_users

depends_on = [
module.app_lb,
module.networking,
]

bucket_kms_key_arns = compact([
local.default_kms_key,
var.bucket_kms_key_arn != "" && var.bucket_kms_key_arn != null ? var.bucket_kms_key_arn : null
Expand Down Expand Up @@ -250,9 +255,10 @@ locals {
weave_trace_sa_name = "wandb-weave-trace"
}

module "wandb" {
source = "wandb/wandb/helm"
version = "2.0.0"
module "wandb_with_cleanup_delay" {
# source = "wandb/wandb/helm"
# version = "2.0.0"
source = "../terraform-helm-wandb"

depends_on = [
module.database,
Expand All @@ -264,6 +270,10 @@ module "wandb" {
controller_image_tag = var.controller_image_tag
enable_helm_release = var.enable_helm_release

redis_master_name = var.redis_master_name
redis_service_name_prefix = var.redis_service_name_prefix
create_redis_in_cluster = var.create_redis_in_cluster

spec = {
values = {
global = {
Expand All @@ -289,8 +299,8 @@ module "wandb" {
}

redis = {
host = module.redis[0].host
port = "${module.redis[0].port}?tls=true&ttlInSeconds=604800"
host = var.use_redis_in_cluster ? "${var.redis_service_name_prefix}-redis" : module.redis[0].host
port = var.use_redis_in_cluster ? "26379?master=${var.redis_master_name}&ttlInSeconds=604800" : "${module.redis[0].port}?tls=true&ttlInSeconds=604800"
}
}

Expand Down Expand Up @@ -358,6 +368,12 @@ module "wandb" {
mysql = { install = false }
redis = { install = false }

redisInCluster = var.use_redis_in_cluster ? {
enabled = true
} : {
enabled = false
}

weave = {
persistence = {
provider = "efs"
Expand Down
12 changes: 7 additions & 5 deletions modules/app_eks/lb_controller/controller.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ locals {
}

resource "helm_release" "aws_load_balancer_controller" {
name = "aws-load-balancer-controller"
repository = "https://aws.github.io/eks-charts"
chart = "aws-load-balancer-controller"
namespace = "kube-system"
version = "1.7.2"
name = "aws-load-balancer-controller"
repository = "https://aws.github.io/eks-charts"
chart = "aws-load-balancer-controller"
namespace = "kube-system"
version = "1.7.2"
wait = true
wait_for_jobs = true

set {
name = "clusterName"
Expand Down
3 changes: 3 additions & 0 deletions modules/app_eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ module "eks" {
metadata_http_put_response_hop_limit = 2
metadata_http_tokens = "required",
version = var.cluster_version,
tags = {
"customer-ns" = var.namespace
}
}

node_groups = {
Expand Down
6 changes: 5 additions & 1 deletion modules/database/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,16 @@ module "aurora" {
performance_insights_retention_period = 7
preferred_backup_window = var.preferred_backup_window
preferred_maintenance_window = var.preferred_maintenance_window
security_group_tags = { "Namespace" : "${var.namespace}" }
security_group_tags = { "Namespace" : var.namespace }
skip_final_snapshot = true
snapshot_identifier = var.snapshot_identifier
storage_encrypted = true
subnets = var.subnets
vpc_id = var.vpc_id

tags = {
Namespace = var.namespace
}


}
4 changes: 4 additions & 0 deletions modules/redis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ resource "aws_elasticache_replication_group" "default" {
kms_key_id = var.kms_key_arn
at_rest_encryption_enabled = true
transit_encryption_enabled = true

tags = {
Namespace = var.namespace
}
}

resource "aws_security_group" "redis" {
Expand Down
24 changes: 24 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,30 @@ variable "elasticache_node_type" {
default = null
}

variable "create_redis_in_cluster" {
type = bool
default = false
description = "Create redis in cluster"
}

variable "use_redis_in_cluster" {
type = bool
default = false
description = "whether to actually use the redis in cluster"
}

variable "redis_service_name_prefix" {
type = string
default = null
description = "Used to infer the service name as `redis-service-name-prefix`-redis.`namespace`"
}

variable "redis_master_name" {
type = string
default = null
description = "Name used by sentinel to identify the set of redis nodes"
}

##########################################
# Weights & Biases #
##########################################
Expand Down
Loading