Skip to content

Commit

Permalink
updates for weave EFS storage class
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyblasczyk committed Dec 15, 2023
1 parent ca761dd commit 9acf6c3
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 3 deletions.
23 changes: 23 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ module "file_storage" {
deletion_protection = var.deletion_protection
}

module "efs" {
source = "./modules/efs"
namespace = var.namespace
private_subnets = module.networking.private_subnets
primary_workers_security_group_id = module.app_eks.primary_workers_security_group_id
vpc_id = module.networking.vpc_id
}

locals {
bucket_name = local.use_external_bucket ? var.bucket_name : module.file_storage.0.bucket_name
bucket_queue_name = local.use_internal_queue ? null : module.file_storage.0.bucket_queue_name
Expand Down Expand Up @@ -241,6 +249,21 @@ module "wandb" {

mysql = { install = false }
redis = { install = false }

weave = {
persistence = {
provider = "efs"
efs = {
fileSystemId = module.efs.efs_id
}

}
}
}
}
}


output "efs_ip" {
value = module.efs.efs_ip
}
6 changes: 4 additions & 2 deletions modules/app_eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ resource "aws_eks_addon" "eks" {
}

resource "aws_eks_addon" "efs" {
cluster_name = var.namespace
addon_name = "aws-efs-csi-driver"
cluster_name = module.eks.cluster_id
addon_name = "aws-efs-csi-driver"
addon_version = "v1.7.1-eksbuild.1" # Ensure this version is compatible
resolve_conflicts = "OVERWRITE"
depends_on = [
module.eks
]
Expand Down
4 changes: 4 additions & 0 deletions modules/app_eks/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ output "autoscaling_group_names" {
output "node_role" {
value = aws_iam_role.node
}

output "primary_workers_security_group_id" {
value = aws_security_group.primary_workers.id
}
49 changes: 49 additions & 0 deletions modules/efs/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
resource "random_pet" "efs" {
length = 2
}

resource "aws_efs_file_system" "storage_class" {
creation_token = "${var.namespace}-${random_pet.efs.id}"
encrypted = true
performance_mode = "generalPurpose"
throughput_mode = "elastic"


tags = {
Name = "${var.namespace}-efs-${random_pet.efs.id}"
}
}

resource "aws_efs_backup_policy" "storage_class" {
file_system_id = aws_efs_file_system.storage_class.id

backup_policy {
status = "DISABLED"
}
}

resource "aws_security_group" "storage_class_nfs" {
name = "nfs-security-group"
description = "Security group for NFS traffic"
vpc_id = var.vpc_id

ingress {
description = "NFS inbound"
from_port = 2049
to_port = 2049
protocol = "tcp"
security_groups = [var.primary_workers_security_group_id]
}

tags = {
Name = "nfs-security-group"
}
}


resource "aws_efs_mount_target" "storage_class" {
for_each = { for subnet in var.private_subnets : subnet => subnet }
file_system_id = aws_efs_file_system.storage_class.id
subnet_id = each.value
security_groups = [aws_security_group.storage_class_nfs.id]
}
3 changes: 3 additions & 0 deletions modules/efs/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "efs_id" {
value = aws_efs_file_system.storage_class.id
}
19 changes: 19 additions & 0 deletions modules/efs/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "namespace" {
description = "The namespace to use for the efs resource"
type = string
}

variable "private_subnets" {
description = "A list of the subnets in which the aws_efs_mount_target will be deployed."
type = list(string)
}

variable "primary_workers_security_group_id" {
description = "The security group ID of the primary workers."
type = string
}

variable "vpc_id" {
description = "The ID of the VPC in which the storage_class_nfs security group will be deployed."
type = string
}
2 changes: 1 addition & 1 deletion modules/file_storage/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ output "bucket_queue_name" {

output "bucket_queue_arn" {
value = var.create_queue ? aws_sqs_queue.file_storage.0.arn : null
}
}

0 comments on commit 9acf6c3

Please sign in to comment.