Skip to content

Commit fe75ec8

Browse files
adding depends on matrix and enable s3_csi_driver (#403)
* adding depends on matrix and enable s3_csi_driver * run fmt * enable csi * enable csi * csi s3 in add list * csi s3 in add list * csi s3 in add list --------- Co-authored-by: Abhi Yerra <abhi@berkeley.edu>
1 parent 903a54e commit fe75ec8

File tree

7 files changed

+63
-26
lines changed

7 files changed

+63
-26
lines changed

cluster.tf

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ resource "aws_eks_addon" "core" {
5454
"vpc-cni",
5555
"coredns",
5656
"aws-ebs-csi-driver",
57+
var.s3_csi_driver_enabled ? ["aws-mountpoint-s3-csi-driver"] : [],
5758
var.efs_enabled ? ["aws-efs-csi-driver"] : [],
5859
]))
5960

examples/eks/main.tf

+7-24
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,11 @@ provider "kubernetes" {
2525
config_path = "./kubeconfig"
2626
}
2727

28-
module "encrypted-launch-template" {
29-
source = "github.com/opszero/terraform-aws-kubespot//module/encrypted-launch-template?ref=developv8"
3028

31-
eks_cluster = module.eks_cluster
32-
eks_cluster_version = "1.29"
33-
}
3429

3530
module "opszero-eks" {
3631
source = "github.com/opszero/terraform-aws-kubespot"
3732

38-
aws_profile = local.profile
3933
zones = [
4034
"us-east-1a",
4135
"us-east-1b"
@@ -78,21 +72,16 @@ module "opszero-eks" {
7872
nodes_max_size = 3,
7973
nodes_min_size = 3
8074
ami_type = "CUSTOM"
81-
launch_template = [{
82-
id = module.encrypted-launch-template.launch_template_id
83-
version = "$Latest"
84-
}]
8575
},
8676
"t3a-medium-spot2" = {
8777
instance_types = [
8878
"t3a.medium",
8979
]
90-
capacity_type = "SPOT"
91-
node_disk_size = 20
80+
node_disk_size = 32
9281
nodes_in_public_subnet = false
93-
node_desired_capacity = 3,
94-
nodes_max_size = 3,
95-
nodes_min_size = 3
82+
node_desired_capacity = 1,
83+
nodes_max_size = 1,
84+
nodes_min_size = 1
9685
}
9786
}
9887

@@ -103,6 +92,9 @@ module "opszero-eks" {
10392
nat_enabled = true
10493
vpc_flow_logs_enabled = false
10594
efs_enabled = false
95+
#csi
96+
s3_csi_driver_enabled = false
97+
s3_csi_bucket_names = ["test-6647373dd"] #name of s3
10698
}
10799

108100
module "helm-common" {
@@ -113,12 +105,3 @@ module "helm-common" {
113105
nginx_max_replicas = 3
114106
}
115107

116-
117-
# resource "aws_ecr_repository" "opszero" {
118-
# name = "opszero"
119-
# image_tag_mutability = "MUTABLE"
120-
121-
# # image_scanning_configuration {
122-
# # scan_on_push = true
123-
# # }
124-
# }

iam.tf

+40
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,43 @@ resource "aws_iam_policy" "ebs" {
384384
}
385385
EOF
386386
}
387+
388+
389+
resource "aws_iam_policy" "s3_policy" {
390+
count = var.s3_csi_driver_enabled ? 1 : 0
391+
name = "${var.environment_name}-s3-access-policy"
392+
description = "IAM policy for S3 access"
393+
394+
policy = jsonencode({
395+
Version = "2012-10-17",
396+
Statement = [
397+
{
398+
Sid = "MountpointFullBucketAccess",
399+
Effect = "Allow",
400+
Action = [
401+
"s3:ListBucket"
402+
],
403+
Resource = [for bucket in var.s3_csi_bucket_names : "arn:aws:s3:::$bucket"]
404+
},
405+
{
406+
Sid = "MountpointFullObjectAccess",
407+
Effect = "Allow",
408+
Action = [
409+
"s3:GetObject",
410+
"s3:PutObject",
411+
"s3:AbortMultipartUpload",
412+
"s3:DeleteObject",
413+
],
414+
Resource = [for bucket in var.s3_csi_bucket_names : "arn:aws:s3:::$bucket/*"]
415+
},
416+
],
417+
})
418+
}
419+
420+
421+
resource "aws_iam_role_policy_attachment" "csi" {
422+
count = var.s3_csi_driver_enabled ? 1 : 0
423+
424+
policy_arn = join("", aws_iam_policy.s3_policy.*.arn)
425+
role = aws_iam_role.node.name
426+
}

metrics_server.tf

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
resource "helm_release" "metrics-server" {
2+
depends_on = [aws_eks_cluster.cluster]
23
name = "metrics-server"
34
repository = "https://kubernetes-sigs.github.io/metrics-server/"
45
chart = "metrics-server"

node.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ resource "aws_autoscaling_group" "asg_nodes" {
100100
value = var.environment_name
101101
propagate_at_launch = true
102102
}
103-
}
103+
}

node_groups.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ resource "aws_launch_template" "encrypted_launch_template" {
4242
no_device = true
4343
ebs {
4444
delete_on_termination = true
45-
volume_size = 2
45+
volume_size = 32
4646
volume_type = "gp3"
4747
encrypted = true
4848
}

variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,15 @@ variable "access_policies" {
442442
description = "access policies"
443443
default = []
444444
}
445+
446+
variable "s3_csi_driver_enabled" {
447+
description = "Enable or disable the S3 CSI driver"
448+
type = bool
449+
default = false
450+
}
451+
452+
variable "s3_csi_bucket_names" {
453+
description = "The name of the S3 bucket for the CSI driver"
454+
type = list(string)
455+
default = [""]
456+
}

0 commit comments

Comments
 (0)