-
Notifications
You must be signed in to change notification settings - Fork 2
/
elb_controller.tf
120 lines (98 loc) · 3.3 KB
/
elb_controller.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# TODO: to finish with regional STS https://docs.aws.amazon.com/eks/latest/userguide/configure-sts-endpoint.html
resource "aws_iam_role" "aws_load_balancer_controller" {
name = "${terraform.workspace}-aws-load-balancer-controller"
description = "${terraform.workspace} aws load balancer controller"
assume_role_policy = templatefile("${path.module}/templates/roles/oidc_aws_load_balancer_controller.pol.tpl", {
aws_account_id = data.aws_caller_identity.current.account_id
oidc = local.oidc_URL
aws_region = var.region
lb_controller_name = var.lb_controller_name
})
tags = merge(
{
"Name" = "${module.generator.prefix}-aws-load-balancer-controller"
},
module.generator.common_tags
)
}
resource "aws_iam_policy" "aws_load_balancer_controller" {
name = "${terraform.workspace}-aws-load-balancer-controller"
policy = file("${path.module}/templates/policies/aws_load_balancer_controller.pol.tpl")
tags = merge(
{
"Name" = "${module.generator.prefix}-aws-load-balancer-controller"
},
module.generator.common_tags
)
}
resource "aws_iam_policy" "aws_load_balancer_controller_additional" {
name = "${terraform.workspace}-aws-load-balancer-controller-additional"
policy = file("${path.module}/templates/policies/aws_load_balancer_controller_additional.pol.tpl")
tags = merge(
{
"Name" = "${module.generator.prefix}-aws-load-balancer-controller-additional"
},
module.generator.common_tags
)
}
resource "aws_iam_role_policy_attachment" "eks_controller_policy" {
role = aws_iam_role.aws_load_balancer_controller.name
policy_arn = aws_iam_policy.aws_load_balancer_controller.arn
}
resource "aws_iam_role_policy_attachment" "eks_controller_policy_additional" {
role = aws_iam_role.aws_load_balancer_controller.name
policy_arn = aws_iam_policy.aws_load_balancer_controller_additional.arn
}
resource "kubernetes_service_account_v1" "alb_controller_service_account" {
metadata {
name = var.lb_controller_name
namespace = "kube-system"
annotations = {
"eks.amazonaws.com/role-arn" = aws_iam_role.aws_load_balancer_controller.arn
}
labels = {
"app.kubernetes.io/component" = "controller"
"app.kubernetes.io/name" = "aws-load-balancer-controller"
}
}
}
# Helm chart url: https://github.com/kubernetes-sigs/aws-load-balancer-controller/tree/main/helm/aws-load-balancer-controller
resource "helm_release" "aws_load_balancer_controller" {
name = "aws-load-balancer-controller"
repository = "https://aws.github.io/eks-charts"
chart = "aws-load-balancer-controller"
namespace = "kube-system"
version = "1.6.2"
set {
name = "vpcId"
value = data.aws_vpc.current.id
}
set {
name = "region"
value = var.region
}
set {
name = "image.repository"
value = "${local.get_registry_based_on_regions}/amazon/aws-load-balancer-controller"
}
set {
name = "image.tag"
value = "v2.5.1"
}
set {
name = "clusterName"
value = terraform.workspace
}
set {
name = "serviceAccount.create"
value = "false"
}
set {
name = "serviceAccount.name"
value = kubernetes_service_account_v1.alb_controller_service_account.metadata[0].name
}
set {
name = "logLevel"
value = "info"
}
}