Skip to content

Commit 5db66fc

Browse files
authored
feat: add configuration of eks version and ability to use existing VPC for cluster (#23)
1 parent e59f8ed commit 5db66fc

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module "vpc" {
5858
source = "terraform-aws-modules/vpc/aws"
5959
version = "5.21.0"
6060
name = var.stack_name
61+
create_vpc = var.stack_existing_vpc_config == null
6162
enable_dns_hostnames = "true"
6263
enable_dns_support = "true"
6364
enable_nat_gateway = "true"
@@ -86,7 +87,7 @@ data "aws_region" "current" {}
8687

8788
# https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/using-govcloud-vpc-endpoints.html
8889
resource "aws_vpc_endpoint" "eks_vpc_endpoints" {
89-
for_each = toset(var.vpc_endpoints)
90+
for_each = var.stack_existing_vpc_config == null ? toset(var.vpc_endpoints) : []
9091
vpc_id = module.vpc.vpc_id
9192
service_name = "com.amazonaws.${data.aws_region.current.name}.${each.value}"
9293
tags = var.stack_tags
@@ -96,16 +97,16 @@ module "eks" {
9697
source = "terraform-aws-modules/eks/aws"
9798
version = "20.36.0"
9899
cluster_name = var.stack_name
99-
cluster_version = "1.31"
100+
cluster_version = var.eks_cluster_version
100101
create = var.stack_create
101102
# TODO: resume usage of node security group; see: https://linear.app/pelotech/issue/PEL-97
102103
create_node_security_group = false
103104
cluster_endpoint_private_access = true
104105
cluster_endpoint_public_access = true
105106
cluster_enabled_log_types = []
106107

107-
subnet_ids = module.vpc.private_subnets
108-
vpc_id = module.vpc.vpc_id
108+
vpc_id = var.stack_existing_vpc_config != null ? var.stack_existing_vpc_config.vpc_id : module.vpc.vpc_id
109+
subnet_ids = var.stack_existing_vpc_config != null ? var.stack_existing_vpc_config.subnet_ids : module.vpc.private_subnets
109110
create_kms_key = true
110111
enable_irsa = true
111112
# cluster_encryption_config = [{

variables.tf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ variable "stack_create" {
88
default = true
99
description = "should resources be created"
1010
}
11+
variable "eks_cluster_version" {
12+
type = string
13+
default = "1.31"
14+
description = "Kubernetes version to set for the cluster"
15+
}
1116
variable "stack_tags" {
1217
type = map(any)
1318
default = {
@@ -16,6 +21,15 @@ variable "stack_tags" {
1621
}
1722
description = "tags to be added to the stack, should at least have Owner and Environment"
1823
}
24+
variable "stack_existing_vpc_config" {
25+
type = object({
26+
vpc_id = string
27+
subnet_ids = list(string)
28+
})
29+
default = null
30+
description = "Setting the VPC"
31+
}
32+
1933
variable "stack_vpc_block" {
2034
type = object({
2135
cidr = string
@@ -143,6 +157,6 @@ variable "s3_csi_driver_bucket_arns" {
143157
}
144158
variable "vpc_endpoints" {
145159
type = list(string)
146-
description = "vpc endpoints within the cluster vpc network"
160+
description = "vpc endpoints within the cluster vpc network, note: this only works when using the internal created VPC"
147161
default = []
148162
}

0 commit comments

Comments
 (0)