-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf.example
More file actions
216 lines (181 loc) · 4.97 KB
/
Copy pathmain.tf.example
File metadata and controls
216 lines (181 loc) · 4.97 KB
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
terraform {
required_providers {
kubernetes = {
version = ">= 2.19.0"
}
}
}
locals {
getssl_service = "getssl"
getssl_worker_version = "0.0.4"
}
resource "kubernetes_persistent_volume_claim_v1" "certs_storage" {
metadata {
name = "getssl-storage-claim"
labels = {
service = local.getssl_service
}
}
wait_until_bound = false
spec {
access_modes = ["ReadWriteOnce"]
storage_class_name = "local-path"
resources {
requests = {
storage = "100Mi"
}
}
}
}
resource "kubernetes_persistent_volume" "certs_storage" {
metadata {
name = "getssl-storage"
labels = {
service = local.getssl_service
name = "getssl-storage"
}
}
spec {
capacity = {
storage = "100Mi"
}
claim_ref {
name = kubernetes_persistent_volume_claim_v1.certs_storage.metadata[0].name
namespace = "default"
}
access_modes = ["ReadWriteOnce"]
}
}
resource "kubernetes_config_map_v1" "config" {
metadata {
name = "getssl-config"
labels = {
service = local.getssl_service
}
}
data = {
wild-example-com = "*.example.com"
example-com = "example.com"
}
}
resource "kubernetes_config_map_v1" "custom_scripts" {
metadata {
name = "getssl-custom-operations"
labels = {
service = local.getssl_service
}
}
data = {
wild-example-com = <<-EOT
CERT_FILE_PATH="$HOME/.getssl/*.example.com/*.example.com"
RELOAD_CMD="your-custom-cert-upload-command '$CERT_FILE_PATH'"
EOT
example-com = <<-EOT
CERT_FILE_PATH="$HOME/.getssl/example.com/example.com"
RELOAD_CMD="your-custom-cert-upload-command '$CERT_FILE_PATH'"
EOT
}
}
resource "kubernetes_cron_job_v1" "getssl" {
metadata {
name = local.getssl_service
labels = {
service = local.getssl_service
}
}
spec {
concurrency_policy = "Replace"
failed_jobs_history_limit = 5
schedule = "0 4 * * *" # Every day at 04:00 am
starting_deadline_seconds = 10
successful_jobs_history_limit = 10
job_template {
metadata {
labels = {
service = local.getssl_service
}
}
spec {
parallelism = 1
backoff_limit = 2
ttl_seconds_after_finished = 24*60*60 # Keep pod for 24 hours for debug purposes
template {
metadata {
labels = {
service = local.getssl_service
}
}
spec {
restart_policy = "Never"
dynamic init_container {
for_each = kubernetes_config_map_v1.config.data
content {
name = "init-${init_container.key}"
image = "askarini/timeweb-getssl:${local.getssl_worker_version}"
command = [
"/bin/sh",
"-c",
"cp -n $HOME/src/getssl.cfg $HOME/.getssl/getssl.cfg && getssl -c \"${init_container.value}\""
]
volume_mount {
name = "store"
mount_path = "/getssl/.getssl"
}
}
}
container {
name = "getssl"
image = "askarini/timeweb-getssl:${local.getssl_worker_version}"
volume_mount {
name = "store"
mount_path = "/getssl/.getssl"
}
dynamic volume_mount {
for_each = kubernetes_config_map_v1.config.data
content {
mount_path = "/getssl/.getssl/${volume_mount.value}/getssl.cfg"
sub_path = volume_mount.key
name = "cert-configs"
}
}
volume_mount {
name = "twc-config"
mount_path = "/run/secrets/timeweb-getssl-twcrc"
sub_path = "timeweb-getssl-twcrc"
}
}
volume {
name = "store"
persistent_volume_claim {
claim_name = kubernetes_persistent_volume_claim_v1.certs_storage.metadata[0].name
}
}
volume {
name = "cert-configs"
config_map {
name = kubernetes_config_map_v1.custom_scripts.metadata.0.name
dynamic items {
for_each = kubernetes_config_map_v1.config.data
content {
key = items.key
path = items.key
}
}
}
}
volume {
name = "twc-config"
secret {
secret_name = "timeweb-secrets"
items {
key = "getssl-twc-config"
path = "timeweb-getssl-twcrc"
}
}
}
}
}
}
}
}
}