Skip to content

Commit

Permalink
FIX - AWS Kubernetes module - update naming to include the key name a…
Browse files Browse the repository at this point in the history
…nd hex id to match other resources
  • Loading branch information
bryan-bar committed Dec 13, 2024
1 parent 12a8d52 commit 4631f5a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
3 changes: 2 additions & 1 deletion edbterraform/data/templates/aws/kubernetes.tf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ module "kubernetes_{{ region_ }}" {

region = each.value.spec.region
desiredCapacity = each.value.spec.node_count
vpcAndClusterPrefix = "${module.spec.base.tags.cluster_name}-${module.spec.pet_name}"
instanceType = each.value.spec.instance_type

name = each.key
name_id = module.spec.hex_id
tags = each.value.spec.tags

providers = {
Expand Down
8 changes: 4 additions & 4 deletions edbterraform/data/terraform/aws/modules/kubernetes/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.9.0"

name = var.vpcAndClusterPrefix
name = local.vpc_name
cidr = var.vpcCidr
azs = data.aws_availability_zones.available.names
private_subnets = [var.privateSubnet1, var.privateSubnet2, var.privateSubnet3]
Expand All @@ -14,12 +14,12 @@ module "vpc" {
enable_dns_hostnames = true

public_subnet_tags = {
"kubernetes.io/cluster/${var.vpcAndClusterPrefix}" = "shared"
"kubernetes.io/cluster/${local.name}" = "shared"
"kubernetes.io/role/elb" = "1"
}

private_subnet_tags = {
"kubernetes.io/cluster/${var.vpcAndClusterPrefix}" = "shared"
"kubernetes.io/cluster/${local.name}" = "shared"
"kubernetes.io/role/internal-elb" = "1"
}

Expand All @@ -30,7 +30,7 @@ module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "20.2.2"

cluster_name = var.vpcAndClusterPrefix
cluster_name = local.name
cluster_version = var.clusterVersion
subnet_ids = module.vpc.private_subnets

Expand Down
18 changes: 14 additions & 4 deletions edbterraform/data/terraform/aws/modules/kubernetes/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ variable "region" {
default = "us-east-1"
}

# NAME SHOULD MAKE USE OF THE SAME ID AS OTHER RESOURCES and the key name, NOT THE PET NAME ID and pre-set prefix
# EX of current naming: EDB-K8s-CNP-lasting-pug
variable "vpcAndClusterPrefix" {
default = "EDB-K8s-CNP"
variable "name" {
default = "K8s-Default-Name"
nullable = false
}

variable "name_id" {
type = string
default = null
nullable = true
}

locals {
name = var.name_id != null && var.name_id != "" ? "${var.name}-${var.name_id}" : var.name
vpc_name = format("eks-%s", local.name)
}

variable "clusterVersion" {
Expand Down

0 comments on commit 4631f5a

Please sign in to comment.