Skip to content

Commit eb83cdd

Browse files
committed
Replace the kubernetes_deployment with a helm_release
1 parent 53e2687 commit eb83cdd

File tree

1 file changed

+46
-121
lines changed

1 file changed

+46
-121
lines changed

main.tf

Lines changed: 46 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -374,130 +374,55 @@ resource "kubernetes_cluster_role_binding" "this" {
374374
}
375375
}
376376

377-
resource "kubernetes_deployment" "this" {
378-
depends_on = [kubernetes_cluster_role_binding.this]
379-
380-
metadata {
381-
name = "aws-alb-ingress-controller"
382-
namespace = var.k8s_namespace
383-
384-
labels = {
385-
"app.kubernetes.io/name" = "aws-alb-ingress-controller"
386-
"app.kubernetes.io/version" = "v${local.aws_alb_ingress_controller_version}"
387-
"app.kubernetes.io/managed-by" = "terraform"
388-
}
377+
resource "helm_release" "using_iamserviceaccount" {
378+
count = var.k8s_cluster_type == "eks" ? 1 : 0
389379

390-
annotations = {
391-
"field.cattle.io/description" = "AWS ALB Ingress Controller"
392-
}
380+
name = "aws-load-balancer-controller"
381+
repository = local.alb_controller_helm_repo
382+
chart = local.alb_controller_chart_name
383+
version = local.alb_controller_chart_version
384+
namespace = "kube-system"
385+
set {
386+
name = "clusterName"
387+
value = var.k8s_cluster_name
393388
}
389+
set {
390+
name = "serviceAccount.create"
391+
value = "false"
392+
}
393+
set {
394+
name = "serviceAccount.name"
395+
value = "aws-load-balancer-controller"
396+
}
397+
set {
398+
name = "region"
399+
value = local.aws_region_name
400+
}
401+
set {
402+
name = "vpcId"
403+
value = local.aws_vpc_id
404+
}
405+
}
394406

395-
spec {
396-
397-
replicas = var.k8s_replicas
398-
399-
selector {
400-
match_labels = {
401-
"app.kubernetes.io/name" = "aws-alb-ingress-controller"
402-
}
403-
}
404-
405-
strategy {
406-
type = "Recreate"
407-
}
408-
409-
template {
410-
metadata {
411-
labels = merge(
412-
{
413-
"app.kubernetes.io/name" = "aws-alb-ingress-controller"
414-
"app.kubernetes.io/version" = local.aws_alb_ingress_controller_version
415-
},
416-
var.k8s_pod_labels
417-
)
418-
annotations = merge(
419-
{
420-
# Annotation which is only used by KIAM and kube2iam.
421-
# Should be ignored by your cluster if using IAM roles for service accounts, e.g.
422-
# when running on EKS.
423-
"iam.amazonaws.com/role" = aws_iam_role.this.arn
424-
},
425-
var.k8s_pod_annotations
426-
)
427-
}
428-
429-
spec {
430-
affinity {
431-
pod_anti_affinity {
432-
preferred_during_scheduling_ignored_during_execution {
433-
weight = 100
434-
pod_affinity_term {
435-
label_selector {
436-
match_expressions {
437-
key = "app.kubernetes.io/name"
438-
operator = "In"
439-
values = ["aws-alb-ingress-controller"]
440-
}
441-
}
442-
topology_key = "kubernetes.io/hostname"
443-
}
444-
}
445-
}
446-
}
447-
448-
automount_service_account_token = true
449-
450-
dns_policy = "ClusterFirst"
451-
452-
restart_policy = "Always"
453-
454-
container {
455-
name = "server"
456-
image = local.aws_alb_ingress_controller_docker_image
457-
image_pull_policy = "Always"
458-
termination_message_path = "/dev/termination-log"
459-
460-
args = [
461-
"--ingress-class=${local.aws_alb_ingress_class}",
462-
"--cluster-name=${var.k8s_cluster_name}",
463-
"--aws-vpc-id=${local.aws_vpc_id}",
464-
"--aws-region=${local.aws_region_name}",
465-
"--aws-max-retries=10",
466-
]
467-
468-
port {
469-
name = "health"
470-
container_port = 10254
471-
protocol = "TCP"
472-
}
473-
474-
readiness_probe {
475-
http_get {
476-
path = "/healthz"
477-
port = "health"
478-
scheme = "HTTP"
479-
}
480-
481-
initial_delay_seconds = 30
482-
period_seconds = 60
483-
timeout_seconds = 3
484-
}
485-
486-
liveness_probe {
487-
http_get {
488-
path = "/healthz"
489-
port = "health"
490-
scheme = "HTTP"
491-
}
492-
493-
initial_delay_seconds = 60
494-
period_seconds = 60
495-
}
496-
}
407+
resource "helm_release" "not_using_iamserviceaccount" {
408+
count = var.k8s_cluster_type == "vanilla" ? 1 : 0
497409

498-
service_account_name = kubernetes_service_account.this.metadata[0].name
499-
termination_grace_period_seconds = 60
500-
}
501-
}
410+
name = "aws-load-balancer-controller"
411+
repository = local.alb_controller_helm_repo
412+
chart = local.alb_controller_chart_name
413+
version = local.alb_controller_chart_version
414+
namespace = "kube-system"
415+
set {
416+
name = "clusterName"
417+
value = var.k8s_cluster_name
418+
}
419+
set {
420+
name = "region"
421+
value = local.aws_region_name
422+
}
423+
set {
424+
name = "vpcId"
425+
value = local.aws_vpc_id
502426
}
503427
}
428+

0 commit comments

Comments
 (0)