forked from Azure-Terraform/terraform-helm-linkerd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
executable file
·203 lines (168 loc) · 5.35 KB
/
main.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
locals {
# set certification expiration date for the number of hours specified
cert_expiration_date = timeadd(timestamp(), "${var.ca_cert_expiration_hours}h")
}
# create certificates for the trust anchor and issuer
#
resource "tls_private_key" "linkerd" {
for_each = toset(["trust_anchor", "issuer"])
algorithm = "ECDSA"
ecdsa_curve = "P256"
}
# Control Plane TLS Credentials
resource "tls_self_signed_cert" "linkerd-trust-anchor" {
key_algorithm = tls_private_key.linkerd["trust_anchor"].algorithm
private_key_pem = tls_private_key.linkerd["trust_anchor"].private_key_pem
is_ca_certificate = true
validity_period_hours = var.trust_anchor_validity_hours
allowed_uses = ["cert_signing", "crl_signing", "server_auth", "client_auth"]
subject {
common_name = "root.linkerd.cluster.local"
}
}
# Webhook TLS Credentials
resource "tls_self_signed_cert" "linkerd-issuer" {
key_algorithm = tls_private_key.linkerd["issuer"].algorithm
private_key_pem = tls_private_key.linkerd["issuer"].private_key_pem
is_ca_certificate = true
validity_period_hours = var.issuer_validity_hours
allowed_uses = ["cert_signing", "crl_signing"]
subject {
common_name = "webhook.linkerd.cluster.local"
}
}
#
# END
# create namespaces for linkerd and any extensions (linkerd-viz or linkerd-jaeger)
resource "kubernetes_namespace" "namespace" {
for_each = var.namespaces
metadata {
name = each.key
annotations = (each.key != "linkerd") ? { "linkerd.io/inject" = "enabled" } : {}
labels = (each.key != "linkerd") ? { "linkerd.io/extension" = trimprefix(each.key, "linkerd-") } : {}
}
}
# create secret used for the control plane credentials
resource "kubernetes_secret" "linkerd-trust-anchor" {
depends_on = [kubernetes_namespace.namespace]
type = "kubernetes.io/tls"
metadata {
name = "linkerd-trust-anchor"
namespace = "linkerd"
}
data = {
"tls.crt" : tls_self_signed_cert.linkerd-trust-anchor.cert_pem
"tls.key" : tls_private_key.linkerd["trust_anchor"].private_key_pem
}
}
# create secrets used for the webhook credentials
resource "kubernetes_secret" "linkerd-issuer" {
depends_on = [kubernetes_namespace.namespace]
type = "kubernetes.io/tls"
for_each = var.namespaces
metadata {
name = "webhook-issuer-tls"
namespace = each.key
}
data = {
"tls.crt" : tls_self_signed_cert.linkerd-issuer.cert_pem
"tls.key" : tls_private_key.linkerd["issuer"].private_key_pem
}
}
resource "helm_release" "issuer" {
depends_on = [kubernetes_secret.linkerd-trust-anchor]
name = "linkerd-issuer"
namespace = "linkerd"
chart = "${path.module}/charts/linkerd-issuers"
values = [
yamlencode({
installLinkerdViz = contains(var.namespaces, "linkerd-viz") ? true : false
installLinkerdJaeger = contains(var.namespaces, "linkerd-jaeger") ? true : false
certificate = {
controlplane = {
duration = var.certificate_controlplane_duration
renewbefore = var.certificate_controlplane_renewbefore
}
webhook = {
duration = var.certificate_webhook_duration
renewbefore = var.certificate_webhook_renewbefore
}
}
})
]
}
resource "helm_release" "linkerd" {
depends_on = [kubernetes_namespace.namespace, helm_release.issuer]
name = "linkerd"
chart = "linkerd2"
repository = var.chart_repository
version = var.chart_version
namespace = "linkerd"
create_namespace = false
values = [
yamlencode({
installNamespace = false
disableHeartBeat = true
identityTrustAnchorsPEM = tls_self_signed_cert.linkerd-trust-anchor.cert_pem
identity = {
issuer = {
scheme = "kubernetes.io/tls"
crtExpiry = local.cert_expiration_date
}
}
proxyInjector = {
caBundle = tls_self_signed_cert.linkerd-issuer.cert_pem
externalSecret = true
}
profileValidator = {
externalSecret = true
caBundle = tls_self_signed_cert.linkerd-issuer.cert_pem
}
}),
var.additional_yaml_config
]
}
resource "helm_release" "linkerd-viz" {
depends_on = [helm_release.linkerd]
count = contains(var.namespaces, "linkerd-viz") ? 1 : 0
name = "linkerd-viz"
chart = "linkerd-viz"
repository = var.chart_repository
version = var.chart_version
namespace = "linkerd-viz"
create_namespace = false
values = [
yamlencode({
installNamespace = false
tap = {
caBundle = tls_self_signed_cert.linkerd-issuer.cert_pem
externalSecret = true
}
tapInjector = {
externalSecret = true
caBundle = tls_self_signed_cert.linkerd-issuer.cert_pem
}
}),
var.additional_yaml_config
]
}
resource "helm_release" "linkerd-jaeger" {
depends_on = [helm_release.linkerd-viz]
count = contains(var.namespaces, "linkerd-jaeger") ? 1 : 0
name = "linkerd-jaeger"
chart = "linkerd-jaeger"
repository = var.chart_repository
version = var.chart_version
namespace = "linkerd-jaeger"
create_namespace = false
values = [
yamlencode({
installNamespace = false
webhook = {
externalSecret = true
caBundle = tls_self_signed_cert.linkerd-issuer.cert_pem
}
}),
var.jaeger_additional_yaml_config
]
}