Skip to content

Commit 402e0ca

Browse files
author
Oded Simon
committed
add secondary subnet config
1 parent 1bfc10a commit 402e0ca

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ locals {
2626
enable_cluster_encryption_config = length(var.cluster_encryption_config) > 0 && !local.create_outposts_local_cluster
2727

2828
auto_mode_enabled = try(var.cluster_compute_config.enabled, false)
29+
optional_pod_subnet_count = length(var.secondary_subnet_ids)
30+
eks_cluster_subnet_count = length(var.subnet_ids)
2931
}
3032

3133
################################################################################
@@ -186,6 +188,24 @@ resource "aws_eks_cluster" "this" {
186188
}
187189
}
188190

191+
resource "kubectl_manifest" "eni_config" {
192+
for_each = local.optional_pod_subnet_count > 0 ? zipmap(var.azs, slice(var.subnet_ids, local.eks_cluster_subnet_count, sum([local.eks_cluster_subnet_count, local.optional_pod_subnet_count]))) : {}
193+
194+
yaml_body = yamlencode({
195+
apiVersion = "crd.k8s.amazonaws.com/v1alpha1"
196+
kind = "ENIConfig"
197+
metadata = {
198+
name = each.key
199+
}
200+
spec = {
201+
securityGroups = [
202+
module.eks.cluster_primary_security_group_id,
203+
]
204+
subnet = each.value
205+
}
206+
})
207+
}
208+
189209
resource "aws_ec2_tag" "cluster_primary_security_group" {
190210
# This should not affect the name of the cluster primary security group
191211
# Ref: https://github.com/terraform-aws-modules/terraform-aws-eks/pull/2006

variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ variable "subnet_ids" {
8686
default = []
8787
}
8888

89+
variable "azs" {
90+
description = "A list of availability zones in the region"
91+
type = list(string)
92+
}
93+
94+
variable "secondary_subnet_ids" {
95+
description = "Optional list of subnets to use for pods.If list is empty, pods will be placed in the subnet_ids subnets. Must be the length of the number of availability zones"
96+
type = list(string)
97+
default = []
98+
}
99+
89100
variable "cluster_endpoint_private_access" {
90101
description = "Indicates whether or not the Amazon EKS private API server endpoint is enabled"
91102
type = bool

versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ terraform {
1414
source = "hashicorp/time"
1515
version = ">= 0.9"
1616
}
17+
kubectl = {
18+
source = "gavinbunney/kubectl"
19+
version = ">= 1.18"
20+
}
1721
}
1822
}

0 commit comments

Comments
 (0)