Skip to content

Commit

Permalink
move EBS storage classes to the cluster workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
baixiac committed Jan 11, 2024
1 parent b06c46f commit 553a895
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 46 deletions.
10 changes: 10 additions & 0 deletions cluster/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
locals {

storage_classes = {
gp2 = "radar-base-ebs-sc-gp2"
gp3 = "radar-base-ebs-sc-gp3"
io1 = "radar-base-ebs-sc-io1"
io2 = "radar-base-ebs-sc-io2"
}

}
24 changes: 8 additions & 16 deletions config/ebs.tf → cluster/ebs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ resource "kubectl_manifest" "ebs_storage_classes" {
type: ${each.key}
fstype: ext4
YAML

depends_on = [
module.eks
]
}

resource "kubernetes_annotations" "unset_eks_default_gp2" {
Expand All @@ -27,6 +31,10 @@ resource "kubernetes_annotations" "unset_eks_default_gp2" {
annotations = {
"storageclass.kubernetes.io/is-default-class" = "false"
}

depends_on = [
module.eks
]
}

resource "kubernetes_annotations" "set_defaut_storage_class" {
Expand All @@ -46,19 +54,3 @@ resource "kubernetes_annotations" "set_defaut_storage_class" {
kubernetes_annotations.unset_eks_default_gp2,
]
}

output "radar_base_ebs_storage_class_gp2" {
value = local.storage_classes.gp2
}

output "radar_base_ebs_storage_class_gp3" {
value = local.storage_classes.gp3
}

output "radar_base_ebs_storage_class_io1" {
value = local.storage_classes.io1
}

output "radar_base_ebs_storage_class_io2" {
value = local.storage_classes.io2
}
35 changes: 35 additions & 0 deletions cluster/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
output "radar_base_eks_cluster_name" {
value = module.eks.cluster_name
}

output "radar_base_eks_cluser_endpoint" {
value = module.eks.cluster_endpoint
}

output "radar_base_eks_dmz_node_group_name" {
value = element(split(":", module.eks.eks_managed_node_groups.dmz.node_group_id), 1)
}

output "radar_base_eks_worker_node_group_name" {
value = element(split(":", module.eks.eks_managed_node_groups.worker.node_group_id), 1)
}

output "radar_base_vpc_public_subnets" {
value = module.vpc.public_subnets
}

output "radar_base_ebs_storage_class_gp2" {
value = local.storage_classes.gp2
}

output "radar_base_ebs_storage_class_gp3" {
value = local.storage_classes.gp3
}

output "radar_base_ebs_storage_class_io1" {
value = local.storage_classes.io1
}

output "radar_base_ebs_storage_class_io2" {
value = local.storage_classes.io2
}
13 changes: 13 additions & 0 deletions cluster/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ provider "kubernetes" {
command = "aws"
}
}

provider "kubectl" {
apply_retry_count = 5
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
load_config_file = false

exec {
api_version = "client.authentication.k8s.io/v1beta1"
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name, "--region", var.AWS_REGION]
command = "aws"
}
}
3 changes: 2 additions & 1 deletion cluster/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
AWS_REGION = "eu-west-2"
environment = "dev"
eks_admins_group_users = []
eks_admins_group_users = []
defaut_storage_class = "radar-base-ebs-sc-gp2"
12 changes: 12 additions & 0 deletions cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,15 @@ variable "eks_admins_group_users" {
description = "EKS admin IAM user group"
default = []
}


variable "defaut_storage_class" {
type = string
description = "Default storage class used for describing the EBS usage"
default = "radar-base-ebs-sc-gp2"

validation {
condition = var.defaut_storage_class == "radar-base-ebs-sc-gp2" || var.defaut_storage_class == "radar-base-ebs-sc-gp3" || var.defaut_storage_class == "radar-base-ebs-sc-io1" || var.defaut_storage_class == "radar-base-ebs-sc-io2"
error_message = "Invalid storage class. Allowed values are 'radar-base-ebs-sc-gp2', 'radar-base-ebs-sc-gp3', 'radar-base-ebs-sc-io1' or 'radar-base-ebs-sc-io2'."
}
}
4 changes: 4 additions & 0 deletions cluster/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ terraform {
source = "hashicorp/kubernetes"
version = "~> 2.24.0"
}
kubectl = {
source = "gavinbunney/kubectl"
version = "~> 1.14.0"
}
}
required_version = ">= 1.4.0, < 1.7.0"
}
7 changes: 0 additions & 7 deletions config/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ locals {
aws_account = element(split(":", data.aws_eks_cluster.main.arn), 4)
oidc_issuer = element(split("//", data.aws_eks_cluster.main.identity[0].oidc[0].issuer), 1)

storage_classes = {
gp2 = "radar-base-ebs-sc-gp2"
gp3 = "radar-base-ebs-sc-gp3"
io1 = "radar-base-ebs-sc-io1"
io2 = "radar-base-ebs-sc-io2"
}

s3_bucket_names = {
intermediate_output_storage = "${var.eks_cluster_name}-intermediate-output-storage"
output_storage = "${var.eks_cluster_name}-output-storage"
Expand Down
21 changes: 10 additions & 11 deletions config/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
AWS_REGION = "eu-west-2"
environment = "dev"
domain_name = "change-me-radar-base-dummy-domain.net"
defaut_storage_class = "radar-base-ebs-sc-gp2"
enable_karpenter = false
enable_msk = false
enable_rds = false
enable_route53 = false
enable_ses = false
enable_s3 = false
enable_eip = false
AWS_REGION = "eu-west-2"
environment = "dev"
domain_name = "change-me-radar-base-dummy-domain.net"
enable_karpenter = true
enable_msk = false
enable_rds = false
enable_route53 = false
enable_ses = false
enable_s3 = true
enable_eip = false
11 changes: 0 additions & 11 deletions config/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ variable "instance_capacity_type" {
}
}

variable "defaut_storage_class" {
type = string
description = "Default storage class used for describing the EBS usage"
default = "radar-base-ebs-sc-gp2"

validation {
condition = var.defaut_storage_class == "radar-base-ebs-sc-gp2" || var.defaut_storage_class == "radar-base-ebs-sc-gp3" || var.defaut_storage_class == "radar-base-ebs-sc-io1" || var.defaut_storage_class == "radar-base-ebs-sc-io2"
error_message = "Invalid storage class. Allowed values are 'radar-base-ebs-sc-gp2', 'radar-base-ebs-sc-gp3', 'radar-base-ebs-sc-io1' or 'radar-base-ebs-sc-io2'."
}
}

variable "kafka_version" {
type = string
default = "3.2.0"
Expand Down

0 comments on commit 553a895

Please sign in to comment.