-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.tf
77 lines (72 loc) · 1.66 KB
/
db.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
resource "kubernetes_namespace" "mongodb_ns" {
metadata { name = var.namespace_name }
}
resource "kubernetes_service" "mongo_service" {
metadata {
name = "mongo"
namespace = kubernetes_namespace.mongodb_ns.metadata[0].name
}
spec {
selector = {
app = "mongo"
}
port {
port = 27017
target_port = 27017
protocol = "TCP"
}
}
}
resource "kubernetes_secret" "mongo_secret" {
metadata {
name = "mongo-env"
namespace = kubernetes_namespace.mongodb_ns.metadata[0].name
}
data = {
"MONGO_INITDB_ROOT_USERNAME" = var.mongo_username
"MONGO_INITDB_ROOT_PASSWORD" = var.mongo_password
}
}
resource "kubernetes_stateful_set" "mongo_statefulset" {
metadata {
name = "mongo"
namespace = kubernetes_namespace.mongodb_ns.metadata[0].name
labels = { app = "mongo" }
}
spec {
replicas = 1
selector {
match_labels = { app = "mongo" }
}
service_name = kubernetes_service.mongo_service.metadata[0].name
template {
metadata {
labels = {
app = "mongo"
}
}
spec {
container {
name = "mongo"
image = "mongo"
volume_mount {
mount_path = "/data/db"
name = "vol-mongo-data"
}
env_from {
secret_ref {
name = kubernetes_secret.mongo_secret.metadata[0].name
}
}
port { container_port = 27017 }
}
volume {
name = "vol-mongo-data"
persistent_volume_claim {
claim_name = kubernetes_persistent_volume_claim.mongodb_pvc.metadata[0].name
}
}
}
}
}
}