-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy paththanos-tls-querier.tf
163 lines (152 loc) · 6.95 KB
/
thanos-tls-querier.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
locals {
thanos-tls-querier = { for k, v in var.thanos-tls-querier : k => merge(
local.helm_defaults,
{
chart = local.helm_dependencies[index(local.helm_dependencies.*.name, "thanos")].name
repository = local.helm_dependencies[index(local.helm_dependencies.*.name, "thanos")].repository
chart_version = local.helm_dependencies[index(local.helm_dependencies.*.name, "thanos")].version
name = "${local.thanos["name"]}-tls-querier-${k}"
enabled = false
generate_cert = local.thanos["generate_ca"]
client_server_name = ""
## This default to Let's encrypt X1 root CA
grpc_client_tls_ca_pem = <<-EOV
-----BEGIN CERTIFICATE-----
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
MTCCAiIwDQYJKoZIhvcN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vjHIInNzktHCgKQ5
ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
-----END CERTIFICATE-----
EOV
stores = []
default_global_requests = false
default_global_limits = false
},
v,
) }
values_thanos-tls-querier = { for k, v in local.thanos-tls-querier : k => merge(
{
values = <<-VALUES
metrics:
enabled: true
serviceMonitor:
enabled: ${local.kube-prometheus-stack["enabled"] ? "true" : "false"}
query:
replicaCount: 2
extraFlags:
- --query.timeout=5m
- --query.lookback-delta=15m
- --query.replica-label=rule_replica
enabled: true
dnsDiscovery:
enabled: false
pdb:
create: true
minAvailable: 1
grpc:
client:
servername: ${v["client_server_name"]}
tls:
enabled: ${v["generate_cert"]}
key: |
${indent(10, v["generate_cert"] ? tls_private_key.thanos-tls-querier-cert-key[k].private_key_pem : "")}
cert: |
${indent(10, v["generate_cert"] ? tls_locally_signed_cert.thanos-tls-querier-cert[k].cert_pem : "")}
ca: |
${indent(10, v["generate_cert"] ? v["grpc_client_tls_ca_pem"] : "")}
stores: ${jsonencode(v["stores"])}
queryFrontend:
enabled: false
compactor:
enabled: false
storegateway:
enabled: false
VALUES
},
v,
) }
}
resource "helm_release" "thanos-tls-querier" {
for_each = { for k, v in local.thanos-tls-querier : k => v if v["enabled"] }
repository = each.value["repository"]
name = each.value["name"]
chart = each.value["chart"]
version = each.value["chart_version"]
timeout = each.value["timeout"]
force_update = each.value["force_update"]
recreate_pods = each.value["recreate_pods"]
wait = each.value["wait"]
atomic = each.value["atomic"]
cleanup_on_fail = each.value["cleanup_on_fail"]
dependency_update = each.value["dependency_update"]
disable_crd_hooks = each.value["disable_crd_hooks"]
disable_webhooks = each.value["disable_webhooks"]
render_subchart_notes = each.value["render_subchart_notes"]
replace = each.value["replace"]
reset_values = each.value["reset_values"]
reuse_values = each.value["reuse_values"]
skip_crds = each.value["skip_crds"]
verify = each.value["verify"]
values = compact([
local.values_thanos-tls-querier[each.key]["values"],
each.value["default_global_requests"] ? local.values_thanos_global_requests : null,
each.value["default_global_limits"] ? local.values_thanos_global_limits : null,
each.value["extra_values"]
])
namespace = local.thanos["create_ns"] ? kubernetes_namespace.thanos.*.metadata.0.name[0] : local.thanos["namespace"]
depends_on = [
helm_release.kube-prometheus-stack,
]
}
resource "tls_private_key" "thanos-tls-querier-cert-key" {
for_each = { for k, v in local.thanos-tls-querier : k => v if v["enabled"] && v["generate_cert"] }
algorithm = "ECDSA"
ecdsa_curve = "P384"
}
resource "tls_cert_request" "thanos-tls-querier-cert-csr" {
for_each = { for k, v in local.thanos-tls-querier : k => v if v["enabled"] && v["generate_cert"] }
private_key_pem = tls_private_key.thanos-tls-querier-cert-key[each.key].private_key_pem
subject {
common_name = each.key
}
dns_names = [
each.key
]
}
resource "tls_locally_signed_cert" "thanos-tls-querier-cert" {
for_each = { for k, v in local.thanos-tls-querier : k => v if v["enabled"] && v["generate_cert"] }
cert_request_pem = tls_cert_request.thanos-tls-querier-cert-csr[each.key].cert_request_pem
ca_private_key_pem = tls_private_key.thanos-tls-querier-ca-key[0].private_key_pem
ca_cert_pem = tls_self_signed_cert.thanos-tls-querier-ca-cert[0].cert_pem
validity_period_hours = 8760
allowed_uses = [
"key_encipherment",
"digital_signature",
"client_auth"
]
}