slack-bot/manifests/common.tf

72 lines
1.7 KiB
HCL

resource "kubernetes_namespace" "monitoring_namespace" {
metadata {
name = "monitoring"
}
}
resource "kubernetes_config_map" "slack_bot_config" {
metadata {
name = "slack-bot-hcl"
namespace = kubernetes_namespace.monitoring_namespace.id
}
data = {
"config.hcl" = <<EOF
bot_id = "${var.bot_id}"
dest_channel_id = "${var.dest_channel_id}"
webhook_id = "${var.webhook_id}"
EOF
}
}
locals {
config_volume_name = "system-bot-volume"
}
resource "kubernetes_cron_job" "slack_bot_checker" {
metadata {
name = "system-cron-bot-job"
namespace = kubernetes_namespace.monitoring_namespace.id
}
spec {
concurrency_policy = "Replace"
failed_jobs_history_limit = 5
# each day at 00:01
schedule = "1 0 * * *"
starting_deadline_seconds = 10
successful_jobs_history_limit = 10
job_template {
metadata {
name = "system-bot-job"
}
spec {
backoff_limit = 2
ttl_seconds_after_finished = 10
template {
metadata {
labels = {
app = "system-bot"
env = var.environment
}
}
spec {
volume {
name = local.config_volume_name
config_map {
name = kubernetes_config_map.slack_bot_config.metadata.0.name
}
}
container {
name = "slackbot"
image = format("docker.registry/slackbot:%s", var.bot_version)
args = ["-config", "/conf/config.hcl"]
volume_mount {
mount_path = "/conf"
name = local.config_volume_name
}
}
}
}
}
}
}
}