Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
c8ebae8
Eng 19422 added irsa
NamelessHH Jul 15, 2020
34dfb04
adding alerts module
NamelessHH Jul 20, 2020
8a8a75c
adding asg recreate on change
bw-henry-he Mar 8, 2021
d23050a
Implement node groups and b-g deploy (#5)
NamelessHH Aug 18, 2021
7d30006
Adding config for eks cluster addons
justinr-bw Aug 24, 2021
1a9c1d0
Merge pull request #6 from BetterWorks/add_eks_addons
justinr-bw Aug 24, 2021
c6a4e4c
fix: Node update fix and clean up (#7)
NamelessHH Nov 8, 2021
39aeaa9
Eng 29912 (#8)
NamelessHH May 19, 2022
a76c0cd
Fix: adding timeouts (#9)
NamelessHH May 28, 2022
77a5969
adding: max_unavailable_percentage (#10)
NamelessHH Sep 27, 2022
ba44028
Sg egress (#11)
NamelessHH Jan 31, 2023
7bb13fc
Terraform 1 (#12)
NamelessHH May 22, 2023
82a0ed3
adding eks csi driver addon & required permissions
lseino-better Jun 4, 2023
e6a12ff
adding eks csi driver addon
lseino-better Jun 4, 2023
c3111c1
adding eks csi driver addon
lseino-better Jun 4, 2023
f9d2677
adding eks csi driver addon
lseino-better Jun 4, 2023
d762159
adding eks csi driver addon
lseino-better Jun 4, 2023
902ab4a
adding eks csi driver addon
lseino-better Jun 5, 2023
cd51a93
Merge pull request #13 from BetterWorks/ENG-39003
lseino-better Aug 7, 2023
6af04c7
adding extra roles needed for Karpenter
lseino-better Aug 7, 2023
189cf90
adding extra roles needed for Karpenter
lseino-better Aug 8, 2023
584b479
Merge pull request #14 from BetterWorks/ENG-40562
lseino-better Aug 8, 2023
0296d31
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
510c7b9
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
c0c6041
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
074b41c
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
ed2d638
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
3462e89
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
2dea855
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
5c30670
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
7331361
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
89cf297
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
48798df
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
4dfc200
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
908ceae
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
1fcfd3f
setting karpenter up with roles && auth config
lseino-better Aug 29, 2023
8a3c304
setting karpenter up with roles && auth config
lseino-better Sep 2, 2023
e111668
setting karpenter up with roles && auth config
lseino-better Sep 2, 2023
b509d61
adding output for karpenter role name
lseino-better Oct 13, 2023
d6ef565
Merge pull request #15 from BetterWorks/ENG-40562
lseino-better Oct 13, 2023
d6f4317
ENG - 40409 - Adding EFS CSI Driver Add-On for EKS (#16)
abhishek25591 Dec 8, 2023
0e5713d
Eng-40409 - Removing karpenter changes to Provision EFS CSI Add-on in…
abhishek25591 Dec 21, 2023
2186621
Karpenter and stability changes (#18)
NamelessHH Feb 14, 2024
7b50032
adding node prefix to node name
lseino-better Jul 19, 2024
c346ab6
adding node prefix to node name
lseino-better Jul 19, 2024
5cd237b
adding node prefix to node name
lseino-better Jul 19, 2024
b7265a8
adding node prefix to node name
lseino-better Jul 19, 2024
fa0cdf3
shortening node group prefix
lseino-better Aug 3, 2024
f1141b1
Merge pull request #19 from BetterWorks/ENG-49167
lseino-better Aug 4, 2024
128caec
fix: hop limit
bw-henry-he Oct 4, 2024
27c93ad
Merge pull request #20 from BetterWorks/ENG-54064
bw-henry-he Oct 17, 2024
85d6135
fix: kms key use
bw-henry-he Nov 4, 2024
debecb2
fix: adding route 53 permissions
bw-henry-he Nov 4, 2024
2c1898e
feat: adding encryption
bw-henry-he Jan 7, 2025
0629911
fix: typo
bw-henry-he Jan 7, 2025
33306a6
fix: duplicates
bw-henry-he Jan 7, 2025
1dbdea8
fix: iam policy
bw-henry-he Jan 7, 2025
7a92c4d
fix: versions
bw-henry-he Jan 7, 2025
cb459c7
Merge pull request #21 from BetterWorks/encryption
bw-henry-he Jan 13, 2025
764ab96
chore: switching cluster to branch for testing
bw-henry-he Jan 31, 2025
7df77ee
Merge pull request #22 from BetterWorks/auth-changes
bw-henry-he Feb 5, 2025
6efd011
Scale coredns (#23)
justinr-bw Apr 9, 2025
1eac6aa
chore: add custom corefile with config changes (#24)
justinr-bw May 7, 2025
a102b44
Add FSx supports
agladboy Sep 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 20 additions & 46 deletions aws_auth.tf
Original file line number Diff line number Diff line change
@@ -1,47 +1,6 @@
data "aws_caller_identity" "current" {
}

data "template_file" "launch_template_worker_role_arns" {
count = var.create_eks ? local.worker_group_launch_template_count : 0
template = file("${path.module}/templates/worker-role.tpl")

vars = {
worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(
coalescelist(
aws_iam_instance_profile.workers_launch_template.*.role,
data.aws_iam_instance_profile.custom_worker_group_launch_template_iam_instance_profile.*.role_name,
),
count.index,
)}"
platform = lookup(
var.worker_groups_launch_template[count.index],
"platform",
local.workers_group_defaults["platform"]
)
}
}

data "template_file" "worker_role_arns" {
count = var.create_eks ? local.worker_group_count : 0
template = file("${path.module}/templates/worker-role.tpl")

vars = {
worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(
coalescelist(
aws_iam_instance_profile.workers.*.role,
data.aws_iam_instance_profile.custom_worker_group_iam_instance_profile.*.role_name,
[""]
),
count.index,
)}"
platform = lookup(
var.worker_groups[count.index],
"platform",
local.workers_group_defaults["platform"]
)
}
}

data "template_file" "node_group_arns" {
count = var.create_eks ? length(module.node_groups.aws_auth_roles) : 0
template = file("${path.module}/templates/worker-role.tpl")
Expand All @@ -52,19 +11,34 @@ data "template_file" "node_group_arns" {
resource "kubernetes_config_map" "aws_auth" {
count = var.create_eks && var.manage_aws_auth ? 1 : 0
depends_on = [null_resource.wait_for_cluster[0]]
#depends_on = [null_resource.wait_for_cluster[0], aws_iam_instance_profile.karpenter_node_instance_profile]

metadata {
name = "aws-auth"
namespace = "kube-system"
}

# data = {
# mapRoles = <<EOF
# ${join("", distinct(concat(data.template_file.node_group_arns.*.rendered)))}
# - rolearn: ${aws_iam_role.karpenter_role[0].arn}
# username: system:node:{{EC2PrivateDNSName}}
# groups:
# - system:bootstrappers
# - system:nodes
# %{if length(var.map_roles) != 0}${yamlencode(var.map_roles)}%{endif}
# EOF

# mapUsers = yamlencode(var.map_users)
# mapAccounts = yamlencode(var.map_accounts)
# }
data = {
mapRoles = <<EOF
${join("", distinct(concat(data.template_file.launch_template_worker_role_arns.*.rendered, data.template_file.worker_role_arns.*.rendered, data.template_file.node_group_arns.*.rendered
${join("", distinct(concat(data.template_file.node_group_arns.*.rendered
)))}
%{if length(var.map_roles) != 0}${yamlencode(var.map_roles)}%{endif}
%{if length(var.map_roles) != 0}${yamlencode(var.map_roles)} %{endif}
EOF
mapUsers = yamlencode(var.map_users)
mapAccounts = yamlencode(var.map_accounts)
}
mapUsers = yamlencode(var.map_users)
mapAccounts = yamlencode(var.map_accounts)
}
}
16 changes: 16 additions & 0 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ resource "aws_eks_cluster" "this" {
version = var.cluster_version
tags = var.tags

access_config {
authentication_mode = "API_AND_CONFIG_MAP"
}

vpc_config {
security_group_ids = [local.cluster_security_group_id]
subnet_ids = var.subnets
Expand All @@ -22,8 +26,20 @@ resource "aws_eks_cluster" "this" {
public_access_cidrs = var.cluster_endpoint_public_access_cidrs
}



dynamic "encryption_config" {
for_each = var.encryption ? [1] : []
content {
provider {
key_arn = aws_kms_key.eks_secrets[0].arn
}
resources = ["secrets"]
}
}
timeouts {
create = var.cluster_create_timeout
update = var.cluster_update_timeout
delete = var.cluster_delete_timeout
}

Expand Down
82 changes: 82 additions & 0 deletions cluster_addons.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Installs/configures add ons for the EKS cluster
resource "aws_eks_addon" "vpc_cni" {
# while we're upgrading we don't want these to be created until we're on 1.20 cluster
count = var.create_eks && var.enable_vpc_cni_addon ? 1 : 0
cluster_name = aws_eks_cluster.this[0].name
addon_name = "vpc-cni"
addon_version = var.vpc_cni_version
resolve_conflicts = var.vpc_cni_resolve_conflicts
}

resource "aws_eks_addon" "coredns" {
count = var.create_eks && var.enable_coredns_addon ? 1 : 0
cluster_name = aws_eks_cluster.this[0].name
addon_name = "coredns"
addon_version = var.coredns_version
resolve_conflicts = var.coredns_resolve_conflicts
configuration_values = jsonencode({
autoScaling = {
enabled = var.coredns_scaling_enabled
minReplicas = var.coredns_minreplicas
maxReplicas = var.coredns_maxreplicas
}
corefile = <<-EOT
.:53 {
errors
health {
lameduck 30s
}
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
forward . /etc/resolv.conf
cache 30 3600 10
loop
reload
loadbalance
}
EOT
})
}

resource "aws_eks_addon" "kube_proxy" {
count = var.create_eks && var.enable_kube_proxy_addon ? 1 : 0
cluster_name = aws_eks_cluster.this[0].name
addon_name = "kube-proxy"
addon_version = var.kube_proxy_version
resolve_conflicts = var.kube_proxy_resolve_conflicts
}

resource "aws_eks_addon" "aws_ebs_csi_driver" {
count = var.create_eks && var.enable_aws_ebs_csi_driver_addon ? 1 : 0
cluster_name = aws_eks_cluster.this[0].name
addon_name = "aws-ebs-csi-driver"
addon_version = var.aws_ebs_csi_driver_version
resolve_conflicts = var.aws_ebs_csi_driver_resolve_conflicts
service_account_role_arn = var.ebs_csi_driver_role_arn
}

# EKS EFS CSI ADD-ON Module
resource "aws_eks_addon" "aws_efs_csi_driver" {
count = var.create_eks && var.enable_aws_efs_csi_driver_addon ? 1 : 0
cluster_name = aws_eks_cluster.this[0].name
addon_name = "aws-efs-csi-driver"
addon_version = var.aws_efs_csi_driver_version
resolve_conflicts = var.aws_efs_csi_driver_resolve_conflicts
service_account_role_arn = var.efs_csi_driver_role_arn
}

# EKS FSx CSI ADD-ON Module
resource "aws_eks_addon" "aws_fsx_csi_driver" {
count = var.create_eks && var.enable_aws_fsx_csi_driver_addon ? 1 : 0
cluster_name = aws_eks_cluster.this[0].name
addon_name = "aws-fsx-csi-driver"
addon_version = var.aws_fsx_csi_driver_version
resolve_conflicts_on_update = var.aws_fsx_csi_driver_resolve_conflicts
service_account_role_arn = module.fsx_csi_irsa[0].iam_role_arn

tags = var.tags
}
136 changes: 2 additions & 134 deletions data.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
locals {
worker_ami_name_filter = var.worker_ami_name_filter != "" ? var.worker_ami_name_filter : "amazon-eks-node-${var.cluster_version}-v*"

# Windows nodes are available from k8s 1.14. If cluster version is less than 1.14, fix ami filter to some constant to not fail on 'terraform plan'.
worker_ami_name_filter_windows = (var.worker_ami_name_filter_windows != "" ?
var.worker_ami_name_filter_windows : "Windows_Server-2019-English-Core-EKS_Optimized-${tonumber(var.cluster_version) >= 1.14 ? var.cluster_version : 1.14}-*"
)
}

data "aws_iam_policy_document" "workers_assume_role_policy" {
Expand Down Expand Up @@ -33,23 +28,6 @@ data "aws_ami" "eks_worker" {
owners = [var.worker_ami_owner_id]
}

data "aws_ami" "eks_worker_windows" {
filter {
name = "name"
values = [local.worker_ami_name_filter_windows]
}

filter {
name = "platform"
values = ["windows"]
}

most_recent = true

owners = [var.worker_ami_owner_id_windows]
}


data "aws_iam_policy_document" "cluster_assume_role_policy" {
statement {
sid = "EKSClusterAssumeRole"
Expand Down Expand Up @@ -103,121 +81,11 @@ EOF

vars = {
value = values(var.kubeconfig_aws_authenticator_env_variables)[count.index]
key = keys(var.kubeconfig_aws_authenticator_env_variables)[count.index]
key = keys(var.kubeconfig_aws_authenticator_env_variables)[count.index]
}
}

data "template_file" "userdata" {
count = var.create_eks ? local.worker_group_count : 0
template = lookup(
var.worker_groups[count.index],
"userdata_template_file",
file(
lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"]) == "windows"
? "${path.module}/templates/userdata_windows.tpl"
: "${path.module}/templates/userdata.sh.tpl"
)
)

vars = merge({
platform = lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"])
cluster_name = aws_eks_cluster.this[0].name
endpoint = aws_eks_cluster.this[0].endpoint
cluster_auth_base64 = aws_eks_cluster.this[0].certificate_authority[0].data
pre_userdata = lookup(
var.worker_groups[count.index],
"pre_userdata",
local.workers_group_defaults["pre_userdata"],
)
additional_userdata = lookup(
var.worker_groups[count.index],
"additional_userdata",
local.workers_group_defaults["additional_userdata"],
)
bootstrap_extra_args = lookup(
var.worker_groups[count.index],
"bootstrap_extra_args",
local.workers_group_defaults["bootstrap_extra_args"],
)
kubelet_extra_args = lookup(
var.worker_groups[count.index],
"kubelet_extra_args",
local.workers_group_defaults["kubelet_extra_args"],
)
},
lookup(
var.worker_groups[count.index],
"userdata_template_extra_args",
local.workers_group_defaults["userdata_template_extra_args"]
)
)
}

data "template_file" "launch_template_userdata" {
count = var.create_eks ? local.worker_group_launch_template_count : 0
template = lookup(
var.worker_groups_launch_template[count.index],
"userdata_template_file",
file(
lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"]) == "windows"
? "${path.module}/templates/userdata_windows.tpl"
: "${path.module}/templates/userdata.sh.tpl"
)
)

vars = merge({
platform = lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"])
cluster_name = aws_eks_cluster.this[0].name
endpoint = aws_eks_cluster.this[0].endpoint
cluster_auth_base64 = aws_eks_cluster.this[0].certificate_authority[0].data
pre_userdata = lookup(
var.worker_groups_launch_template[count.index],
"pre_userdata",
local.workers_group_defaults["pre_userdata"],
)
additional_userdata = lookup(
var.worker_groups_launch_template[count.index],
"additional_userdata",
local.workers_group_defaults["additional_userdata"],
)
bootstrap_extra_args = lookup(
var.worker_groups_launch_template[count.index],
"bootstrap_extra_args",
local.workers_group_defaults["bootstrap_extra_args"],
)
kubelet_extra_args = lookup(
var.worker_groups_launch_template[count.index],
"kubelet_extra_args",
local.workers_group_defaults["kubelet_extra_args"],
)
},
lookup(
var.worker_groups_launch_template[count.index],
"userdata_template_extra_args",
local.workers_group_defaults["userdata_template_extra_args"]
)
)
}

data "aws_iam_role" "custom_cluster_iam_role" {
count = var.manage_cluster_iam_resources ? 0 : 1
name = var.cluster_iam_role_name
}

data "aws_iam_instance_profile" "custom_worker_group_iam_instance_profile" {
count = var.manage_worker_iam_resources ? 0 : local.worker_group_count
name = lookup(
var.worker_groups[count.index],
"iam_instance_profile_name",
local.workers_group_defaults["iam_instance_profile_name"],
)
}

data "aws_iam_instance_profile" "custom_worker_group_launch_template_iam_instance_profile" {
count = var.manage_worker_iam_resources ? 0 : local.worker_group_launch_template_count
name = lookup(
var.worker_groups_launch_template[count.index],
"iam_instance_profile_name",
local.workers_group_defaults["iam_instance_profile_name"],
)
name = var.cluster_iam_role_name
}
Loading
Loading