-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.tf
131 lines (130 loc) · 3.26 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
resource "humanitec_resource_definition" "main" {
id = "${var.prefix}mongodb"
name = "${var.prefix}mongodb"
type = "mongodb"
driver_type = "humanitec/template"
driver_inputs = {
values_string = jsonencode({
templates = {
cookie = <<EOL
rootUsername: {{ .init.rootUsername }}
name: {{ .init.name }}
rootPassword: {{ .init.rootPassword }}
port: {{ .init.port }}
EOL
init = <<EOL
{{- if .cookie}}
rootUsername: {{ .cookie.rootUsername }}
name: {{ .cookie.name }}
rootPassword: {{ .cookie.rootPassword }}
port: {{ .cookie.port }}
{{- else }}
rootUsername: {{ randAlpha 8 | lower | quote }}
rootPassword: {{ randAlphaNum 16 | quote }}
name: db_{{ randAlpha 10}}
port: 27017
{{- end }}
id: mongodb-{{ .id }}
EOL
manifests = <<EOL
deployment.yaml:
location: namespace
data:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .init.id }}
spec:
selector:
matchLabels:
app: {{ .init.id }}
template:
metadata:
labels:
app: {{ .init.id }}
spec:
automountServiceAccountToken: false
containers:
- name: mongodb
image: mongo:8
ports:
- containerPort: {{ .init.port }}
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: {{ .init.rootUsername }}
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .init.id }}
key: MONGO_INITDB_ROOT_PASSWORD
securityContext:
runAsUser: 1001
runAsGroup: 1001
allowPrivilegeEscalation: false
privileged: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
volumeMounts:
- name: data
mountPath: /data/db
- name: tmp
mountPath: /tmp
securityContext:
runAsNonRoot: true
fsGroup: 1001
seccompProfile:
type: RuntimeDefault
volumes:
- name: data
persistentVolumeClaim:
claimName: pvc-{{ .init.id }}
- name: tmp
emptyDir: {}
pvc.yaml:
location: namespace
data:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-{{ .init.id }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1G
service.yaml:
location: namespace
data:
apiVersion: v1
kind: Service
metadata:
name: {{ .init.id }}
spec:
type: ClusterIP
selector:
app: {{ .init.id }}
ports:
- name: tcp-mongodb
port: {{ .init.port }}
targetPort: {{ .init.port }}
secret.yaml:
location: namespace
data:
apiVersion: v1
kind: Secret
metadata:
name: {{ .init.id }}
type: Opaque
data:
MONGO_INITDB_ROOT_PASSWORD: {{ .init.rootPassword | b64enc }}
EOL
secrets = <<EOL
connection: mongodb://{{ .init.rootUsername }}:{{ .init.rootPassword }}@{{ .init.id }}:{{ .init.port }}/
EOL
}
})
}
}