-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
121 lines (117 loc) · 3.25 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
locals {
default_tolerations = [
{
key = "altinity.cloud/use"
value = "anywhere"
effect = "NoSchedule"
operator = "Equal"
}
]
}
resource "kubernetes_secret_v1" "altinitycloud_cloud_connect" {
# https://www.terraform.io/language/state/sensitive-data
count = var.use_external_secret ? 0 : 1
metadata {
name = "cloud-connect"
namespace = kubernetes_namespace_v1.altinitycloud_system.metadata[0].name
labels = {
app = "cloud-connect"
}
}
data = {
"cloud-connect.pem" = var.pem
}
}
resource "kubernetes_deployment_v1" "altinitycloud_cloud_connect" {
metadata {
name = "cloud-connect"
namespace = kubernetes_namespace_v1.altinitycloud_system.metadata[0].name
labels = {
app = "cloud-connect"
}
}
spec {
replicas = 1
revision_history_limit = 3
selector {
match_labels = {
app = "cloud-connect"
}
}
template {
metadata {
labels = {
app = "cloud-connect"
}
annotations = {
"prometheus.io/scrape" = "true"
"prometheus.io/port" = "7777"
}
}
spec {
service_account_name = "cloud-connect"
volume {
name = "secret"
secret {
secret_name = "cloud-connect"
}
}
container {
name = "cloud-connect"
image = var.image != "" ? var.image : "altinity/cloud-connect:${local.version}"
image_pull_policy = var.image_pull_policy != "" ? var.image_pull_policy : local.version == "latest-master" ? "Always" : "IfNotPresent"
args = [
"-u",
var.url,
"-i",
"/etc/cloud-connect/cloud-connect.pem",
"--debug-addr",
":7777"
]
volume_mount {
name = "secret"
mount_path = "/etc/cloud-connect"
}
liveness_probe {
http_get {
path = "/healthz"
port = 7777
}
initial_delay_seconds = 5
period_seconds = 5
}
}
dynamic "toleration" {
for_each = concat(local.default_tolerations, var.tolerations)
content {
key = toleration.value.key
operator = toleration.value.operator
value = toleration.value.value
effect = toleration.value.effect
}
}
}
}
}
wait_for_rollout = !var.use_external_secret
depends_on = [
// delay deployment until secret is created
kubernetes_secret_v1.altinitycloud_cloud_connect
]
}
resource "null_resource" "wait" {
count = var.wait_connected || var.wait_ready ? 1 : 0
triggers = {
hash = sha256(join("\n", [var.url, var.pem])),
}
provisioner "local-exec" {
command = "${path.module}/statuscheck --url=${var.url} --cert=<(echo $STATUSCHECK_CERT_BASE64 | base64 -d) --wait=${var.wait_timeout_in_seconds} ${!var.wait_ready ? "--connected" : ""}"
interpreter = ["/usr/bin/env", "bash", "-c"]
environment = {
STATUSCHECK_CERT_BASE64 = base64encode(var.pem)
}
}
depends_on = [
kubernetes_deployment_v1.altinitycloud_cloud_connect
]
}