Skip to content

Commit

Permalink
Merge pull request #208 from kbst/eksvpcrefactor
Browse files Browse the repository at this point in the history
EKS: Allow custom CIDRs for the VPC and its per AZ default subnets
  • Loading branch information
pst authored Aug 23, 2021
2 parents b6c35ce + b9d29d2 commit b070825
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
10 changes: 10 additions & 0 deletions aws/_modules/eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ variable "availability_zones" {
type = list(string)
}

variable "vpc_cidr" {
description = "CIDR to use for the VPC."
type = string
}

variable "vpc_subnet_newbits" {
description = "CIDR to use for the VPC."
type = string
}

variable "instance_type" {
description = "AWS instance type to use for worker nodes."
type = string
Expand Down
4 changes: 2 additions & 2 deletions aws/_modules/eks/vpc.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_vpc" "current" {
cidr_block = "10.0.0.0/16"
cidr_block = var.vpc_cidr

tags = local.eks_metadata_tags
}
Expand All @@ -8,7 +8,7 @@ resource "aws_subnet" "current" {
count = length(var.availability_zones)

availability_zone = var.availability_zones[count.index]
cidr_block = "10.0.${count.index}.0/24"
cidr_block = cidrsubnet(aws_vpc.current.cidr_block, var.vpc_subnet_newbits, count.index)
vpc_id = aws_vpc.current.id
map_public_ip_on_launch = true

Expand Down
3 changes: 3 additions & 0 deletions aws/cluster/configuration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ locals {
cluster_availability_zones_lookup = lookup(local.cfg, "cluster_availability_zones", "")
cluster_availability_zones = split(",", local.cluster_availability_zones_lookup)

cluster_vpc_cidr = lookup(local.cfg, "cluster_vpc_cidr", "10.0.0.0/16")
cluster_vpc_subnet_newbits = lookup(local.cfg, "cluster_vpc_subnet_newbits", "8")

cluster_instance_type = local.cfg["cluster_instance_type"]

cluster_desired_capacity = local.cfg["cluster_desired_capacity"]
Expand Down
13 changes: 8 additions & 5 deletions aws/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ module "cluster" {
metadata_labels = module.cluster_metadata.labels

availability_zones = local.cluster_availability_zones
instance_type = local.cluster_instance_type
desired_capacity = local.cluster_desired_capacity
max_size = local.cluster_max_size
min_size = local.cluster_min_size
cluster_version = local.cluster_version
vpc_cidr = local.cluster_vpc_cidr
vpc_subnet_newbits = local.cluster_vpc_subnet_newbits

instance_type = local.cluster_instance_type
desired_capacity = local.cluster_desired_capacity
max_size = local.cluster_max_size
min_size = local.cluster_min_size
cluster_version = local.cluster_version

root_device_encrypted = local.worker_root_device_encrypted
root_device_volume_size = local.worker_root_device_volume_size
Expand Down

0 comments on commit b070825

Please sign in to comment.