Skip to content

Commit

Permalink
Do not set any service CIDR unless user sets it
Browse files Browse the repository at this point in the history
The approach I'm taking here leaves the attribute null.

If not set by the user, whatever EKS uses as the default
will be used. If the user overwrites it, their value will
be used.

I prefer this approach, because I do not have to concern
myself at all with whatever the EKS default is.
  • Loading branch information
pst committed Oct 6, 2023
1 parent fae3394 commit 34d61c4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions aws/_modules/eks/master.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ resource "aws_eks_cluster" "current" {
public_access_cidrs = var.cluster_public_access_cidrs
}

kubernetes_network_config {
service_ipv4_cidr = var.cluster_service_cidr
dynamic "kubernetes_network_config" {
for_each = var.cluster_service_cidr != null ? toset([1]) : toset([])
content {
service_ipv4_cidr = var.cluster_service_cidr
}
}

dynamic "encryption_config" {
Expand Down
2 changes: 1 addition & 1 deletion aws/_modules/eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ variable "cluster_public_access_cidrs" {
variable "cluster_service_cidr" {
type = string
default = null
description = "Sets the Service CIDR for the EKS cluster. EKS defaults this to 172.20.0.0/0."
description = "Sets the Service CIDR for the EKS cluster."
}

variable "cluster_encryption_key_arn" {
Expand Down
2 changes: 1 addition & 1 deletion aws/cluster/configuration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ locals {
cluster_endpoint_public_access = lookup(local.cfg, "cluster_endpoint_public_access", true)
cluster_public_access_cidrs_lookup = lookup(local.cfg, "cluster_public_access_cidrs", null)
cluster_public_access_cidrs = local.cluster_public_access_cidrs_lookup == null ? null : split(",", local.cluster_public_access_cidrs_lookup)
cluster_service_cidr = lookup(local.cfg, "cluster_service_cidr", "172.20.0.0/16")
cluster_service_cidr = lookup(local.cfg, "cluster_service_cidr", null)

cluster_encryption_key_arn = lookup(local.cfg, "cluster_encryption_key_arn", null)
}

0 comments on commit 34d61c4

Please sign in to comment.