-
Notifications
You must be signed in to change notification settings - Fork 0
/
alb_controller.tf
71 lines (58 loc) · 2.18 KB
/
alb_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
locals {
lb_controller_iam_role_name = "inhouse-eks-aws-lb-ctrl"
lb_controller_service_account_name = "aws-load-balancer-controller"
}
data "aws_eks_cluster_auth" "this" {
name = local.cluster_name
}
provider "helm" {
kubernetes {
host = module.eks.cluster_endpoint
token = data.aws_eks_cluster_auth.this.token
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
}
}
module "lb_controller_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
create_role = true
role_name = local.lb_controller_iam_role_name
role_path = "/"
role_description = "Used by AWS Load Balancer Controller for EKS"
role_permissions_boundary_arn = ""
provider_url = replace(module.eks.cluster_oidc_issuer_url, "https://", "")
oidc_fully_qualified_subjects = [
"system:serviceaccount:kube-system:${local.lb_controller_service_account_name}"
]
oidc_fully_qualified_audiences = [
"sts.amazonaws.com"
]
}
data "http" "iam_policy" {
url = "https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.4.0/docs/install/iam_policy.json"
}
resource "aws_iam_role_policy" "controller" {
name_prefix = "AWSLoadBalancerControllerIAMPolicy"
policy = data.http.iam_policy.body
role = module.lb_controller_role.iam_role_name
}
resource "helm_release" "release" {
name = "aws-load-balancer-controller"
chart = "aws-load-balancer-controller"
repository = "https://aws.github.io/eks-charts"
namespace = "kube-system"
dynamic "set" {
for_each = {
"clusterName" = module.eks.cluster_id
"serviceAccount.create" = "true"
"serviceAccount.name" = local.lb_controller_service_account_name
"region" = "ap-northeast-2"
"vpcId" = module.vpc.vpc_id
"image.repository" = "602401143452.dkr.ecr.ap-northeast-2.amazonaws.com/amazon/aws-load-balancer-controller"
"serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn" = module.lb_controller_role.iam_role_arn
}
content {
name = set.key
value = set.value
}
}
}