-
Notifications
You must be signed in to change notification settings - Fork 13
/
addons.tf
155 lines (142 loc) · 3.76 KB
/
addons.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
module "ebs_csi_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "5.34.0"
role_name = "irsa-ebs-csi"
attach_ebs_csi_policy = true
oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["kube-system:ebs-csi-controller-sa"]
}
}
depends_on = [
null_resource.cluster_ready
]
}
resource "kubernetes_annotations" "default-storageclass" {
api_version = "storage.k8s.io/v1"
kind = "StorageClass"
force = "true"
metadata {
name = "gp2"
}
annotations = {
"storageclass.kubernetes.io/is-default-class" = "false"
}
depends_on = [
null_resource.cluster_ready
]
}
resource "helm_release" "ebs_csi_driver" {
name = "aws-ebs-csi-driver"
chart = "aws-ebs-csi-driver"
repository = "https://kubernetes-sigs.github.io/aws-ebs-csi-driver"
namespace = "kube-system"
version = "2.28.1"
values = [
<<EOF
controller:
serviceAccount:
annotations:
eks.amazonaws.com/role-arn: ${module.ebs_csi_role.iam_role_arn}
storageClasses:
- name: ebs-sc
annotations:
storageclass.kubernetes.io/is-default-class: "true"
EOF
]
depends_on = [
null_resource.cluster_ready
]
}
## DNS Setup
module "external_dns_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "5.34.0"
role_name = "external-dns"
attach_external_dns_policy = true
oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["external-dns:external-dns"]
}
}
depends_on = [
null_resource.cluster_ready
]
}
resource "helm_release" "external_dns" {
name = "external-dns"
chart = "external-dns"
repository = "https://kubernetes-sigs.github.io/external-dns/"
namespace = "external-dns"
create_namespace = true
version = "1.14.0"
values = [
<<-EOF
sources:
- istio-gateway
provider: aws
env:
- name: AWS_REGION
serviceAccount:
annotations:
eks.amazonaws.com/role-arn: ${module.external_dns_role.iam_role_arn}
securityContext:
fsGroup: 1001
EOF
]
depends_on = [
null_resource.cluster_ready
]
}
## HTTPS Setup
module "cert_manager_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "5.34.0"
role_name = "cert-manager"
attach_cert_manager_policy = true
oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["cert-manager:cert-manager"]
}
}
}
resource "helm_release" "cert_manager" {
name = "cert-manager"
namespace = "cert-manager"
chart = "cert-manager"
repository = "https://charts.jetstack.io"
version = "1.12.8"
create_namespace = true
depends_on = [
helm_release.external_dns
]
values = [
<<EOF
installCRDs: true
serviceAccount:
annotations:
eks.amazonaws.com/role-arn: ${module.cert_manager_role.iam_role_arn}
securityContext:
fsGroup: 1001
extraArgs:
- --issuer-ambient-credentials=true
- --cluster-issuer-ambient-credentials=true
EOF
]
}
resource "null_resource" "core_addons" {
# triggers = {
# always_run = "${timestamp()}"
# }
provisioner "local-exec" {
when = destroy
command = "echo 'Waiting for addons to cleanup DNS/Loadbalancers' && sleep 60"
}
depends_on = [
helm_release.ebs_csi_driver,
helm_release.cert_manager
]
}