-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathonp_cluster_secrets.tf
307 lines (247 loc) · 8.83 KB
/
onp_cluster_secrets.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# 複数 Namespace 間で共有する秘匿値があるので、ClusterSecret controller を利用する
resource "helm_release" "onp_cluster_clustersecret" {
depends_on = [kubernetes_namespace.onp_clustersecret]
# https://github.com/zakkg3/ClusterSecret/tree/bab429d98b9da19debf97259fdba01211fa8dd43#using-the-official-helm-chart
repository = "https://charts.clustersecret.io/"
chart = "cluster-secret"
name = "clustersecret"
namespace = "kube-system"
version = "0.4.1"
reset_values = true
recreate_pods = true
cleanup_on_fail = true
}
resource "kubernetes_secret" "onp_argocd_github_oauth_app_secret" {
depends_on = [kubernetes_namespace.onp_argocd]
metadata {
name = "argocd-github-oauth-app-secret"
namespace = "argocd"
labels = {
# これが必要っぽい
# https://argo-cd.readthedocs.io/en/stable/operator-manual/user-management/#alternative
"app.kubernetes.io/part-of" = "argocd"
}
}
data = {
ARGOCD_GITHUB_OAUTH_APP_SECRET = var.onp_k8s_argocd_github_oauth_app_secret
}
type = "Opaque"
}
resource "kubernetes_secret" "onp_argocd_applicationset_controller_github_app_secret" {
depends_on = [kubernetes_namespace.onp_argocd]
metadata {
name = "argocd-applicationset-controller-github-app-secret"
namespace = "argocd"
labels = {
# seichi_infra 向けのアクセストークンであると決め打ちする 必要に応じて repo-creds にするなどすると良い
# repo-creds の詳細: https://argo-cd.readthedocs.io/en/stable/operator-manual/declarative-setup/#repository-credentials
"argocd.argoproj.io/secret-type" = "repository"
}
}
data = {
type = "git"
url = "https://github.com/GiganticMinecraft/seichi_infra"
githubAppID = var.onp_k8s_argocd_applicationset_controller_github_app_id
githubAppInstallationID = var.onp_k8s_argocd_applicationset_controller_github_app_installation_id
githubAppPrivateKey = var.onp_k8s_argocd_applicationset_controller_github_app_pem
}
type = "Opaque"
}
resource "kubernetes_secret" "onp_argocd_workflows_sso" {
depends_on = [kubernetes_namespace.onp_argocd]
metadata {
name = "argo-workflows-sso"
namespace = "argocd"
}
data = {
client-id = "argo-workflows-sso"
client-secret = var.onp_k8s_argo_workflows_sso_client_secret
}
type = "Opaque"
}
resource "kubernetes_secret" "onp_argo_workflows_sso" {
depends_on = [kubernetes_namespace.onp_argo]
metadata {
name = "argo-workflows-sso"
namespace = "argo"
}
data = {
client-id = "argo-workflows-sso"
client-secret = var.onp_k8s_argo_workflows_sso_client_secret
}
type = "Opaque"
}
resource "kubernetes_secret" "onp_grafana_github_oauth_app_secret" {
depends_on = [kubernetes_namespace.onp_monitoring]
metadata {
name = "grafana-github-oauth-app-secret"
namespace = "monitoring"
}
data = {
GF_AUTH_GITHUB_CLIENT_ID = var.onp_k8s_grafana_github_oauth_app_id
GF_AUTH_GITHUB_CLIENT_SECRET = var.onp_k8s_grafana_github_oauth_app_secret
}
type = "Opaque"
}
resource "kubernetes_secret" "onp_synology_csi" {
depends_on = [kubernetes_namespace.onp_synology_csi]
metadata {
name = "client-info-secret"
namespace = "synology-csi"
}
data = {
"client-info.yml" = var.onp_k8s_synology_csi_config
}
type = "Opaque"
}
resource "kubernetes_secret" "cloudflared_tunnel_credential" {
depends_on = [kubernetes_namespace.cloudflared_tunnel_exits]
metadata {
name = "cloudflared-tunnel-credential"
namespace = "cloudflared-tunnel-exits"
}
# cloudflared-tunnel Helm chart がこの形式の Secret を想定している。
# どのようにこの Secret を Pod が利用しているかについては、
# helm-charts/cloudflared-tunnel/deployment.yaml を参照のこと。
data = {
"TUNNEL_CREDENTIAL" = var.onp_k8s_cloudflared_tunnel_credential
}
type = "Opaque"
}
resource "kubernetes_secret" "minio_root_user" {
depends_on = [kubernetes_namespace.minio]
metadata {
name = "minio-root-user"
namespace = "minio"
}
data = {
"rootUser" = "root"
"rootPassword" = var.minio_root_password
}
type = "Opaque"
}
resource "kubernetes_secret" "minio_prod_access_secret" {
depends_on = [kubernetes_namespace.onp_seichi_minecraft]
metadata {
name = "minio-access-secret"
namespace = "seichi-minecraft"
}
data = {
"MINIO_ACCESS_KEY" = var.minio_prod_access_key
"MINIO_ACCESS_SECRET" = var.minio_prod_access_secret
}
type = "Opaque"
}
resource "kubernetes_secret" "minio_debug_access_secret" {
depends_on = [kubernetes_namespace.onp_seichi_debug_minecraft]
metadata {
name = "minio-access-secret"
namespace = "seichi-debug-minecraft"
}
data = {
"MINIO_ACCESS_KEY" = var.minio_debug_access_key
"MINIO_ACCESS_SECRET" = var.minio_debug_access_secret
}
type = "Opaque"
}
resource "random_password" "minecraft__prod_mariadb_monitoring_password" {
length = 16
special = false // MariaDBのパスワードがぶっ壊れて困るので記号を含めない
}
resource "helm_release" "onp_minecraft_mariadb_monitoring_password" {
depends_on = [helm_release.onp_cluster_clustersecret]
# ClusterSecret controller も helm_release で入れている (onp_cluster_clustersecret) ため、
# kubernetes_manifest リソースで ClusterSecret を入れようとすると、controller と ClusterSecret 両方を
# (クラスタ再作成時等に) 作成する際に plan が失敗し、apply できなくなる。
# https://github.com/hashicorp/terraform-provider-kubernetes/issues/1583
#
# これを回避するため、 values.yaml 内の manifest をそのまま apply するような Helm chart を作成し、
# それを経由して ClusterSecret を作成する。こうすると、Terraform は ClusterSecret manifest の diff を取らずに
# `onp_minecraft_mariadb_monitoring_password` に対応する Helm release が存在するかどうかだけを見るようになるので、
# 上手くいく。
repository = "https://giganticminecraft.github.io/seichi_infra/"
chart = "raw-resources"
name = "mariadb-monitoring-password-raw-resource"
namespace = "kube-system"
version = "0.3.0"
set_list {
name = "manifests"
value = [<<-EOS
kind: ClusterSecret
apiVersion: clustersecret.io/v1
metadata:
namespace: clustersecret
name: mariadb-monitoring-password
matchNamespace:
- monitoring
- seichi-minecraft
- seichi-debug-minecraft-on-seichiassist-pr-*
data:
monitoring-password: ${base64encode(random_password.minecraft__prod_mariadb_monitoring_password.result)}
EOS
]
}
}
resource "random_password" "minecraft__pr_review_mariadb_root_password" {
length = 16
special = false // MariaDBのパスワードがぶっ壊れて困るので記号を含めない
}
resource "random_password" "minecraft__pr_review_mariadb_password" {
length = 16
special = false // MariaDBのパスワードがぶっ壊れて困るので記号を含めない
}
resource "helm_release" "onp_minecraft__pr_review_mariadb_password" {
depends_on = [helm_release.onp_cluster_clustersecret]
repository = "https://giganticminecraft.github.io/seichi_infra/"
chart = "raw-resources"
name = "mariadb-pr-review-password-raw-resource"
namespace = "kube-system"
version = "0.3.0"
set_list {
name = "manifests"
value = [<<-EOS
kind: ClusterSecret
apiVersion: clustersecret.io/v1
metadata:
namespace: clustersecret
name: mariadb-pr-review-password
matchNamespace:
- seichi-debug-minecraft-on-seichiassist-pr-*
data:
root-password: ""
mcserver-password: ""
prod-mariadb-password: ${base64encode(var.minecraft__prod_game_db__password)}
EOS
]
}
}
resource "kubernetes_secret" "idea_reaction_discord_token" {
depends_on = [kubernetes_namespace.onp_seichi_minecraft]
metadata {
name = "idea-reaction-discord-token"
namespace = "seichi-minecraft"
}
data = {
IDEA_REACTION_DISCORD_TOKEN = var.discord_bot__idea_reaction__discord_token
}
}
resource "kubernetes_secret" "idea_reaction_redmine_api_key" {
depends_on = [kubernetes_namespace.onp_seichi_minecraft]
metadata {
name = "idea-reaction-redmine-api-key"
namespace = "seichi-minecraft"
}
data = {
IDEA_REACTION_REDMINE_API_KEY = var.discord_bot__idea_reaction__redmine_api_key
}
}
resource "kubernetes_secret" "babyrite_discord_token" {
depends_on = [kubernetes_namespace.onp_seichi_minecraft]
metadata {
name = "babyrite-discord-token"
namespace = "seichi-minecraft"
}
data = {
BABYRITE_DISCORD_TOKEN = var.discord_bot__babyrite__discord_token
}
}