osrsscrape/main.tf

100 lines
2.3 KiB
Terraform
Raw Permalink Normal View History

2023-07-12 23:54:48 -07:00
terraform {
backend "local" {}
2023-07-13 23:44:19 -07:00
required_version = ">= 1.5"
2023-07-12 23:54:48 -07:00
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.3.2"
}
}
}
provider "kubernetes" {
config_path = "~/.kube/config"
config_context = "scck8s"
}
variable "players" {
type = map(object({
alias = optional(string)
2023-07-13 23:44:19 -07:00
suspend = optional(bool, false)
image = optional(string, "dockermirror:5000/dpedu/rsscrape")
dryrun = optional(bool, false)
2023-07-12 23:54:48 -07:00
schedule = optional(string)
}))
description = "players to scrape"
}
variable "influx_url" {
type = string
description = "influxdb connection url"
}
variable "namespace" {
type = string
default = "jobs"
}
variable "schedule" {
type = string
description = "kube cron expression"
default = "*/10 * * * *"
}
resource "kubernetes_cron_job" "scraper" {
2023-07-13 23:44:19 -07:00
for_each = var.players
2023-07-12 23:54:48 -07:00
metadata {
2023-07-13 23:44:19 -07:00
name = "rsscrape-${lower(replace(replace(each.key, " ", "-"), "_", "-"))}"
2023-07-12 23:54:48 -07:00
namespace = var.namespace
}
spec {
2023-07-13 23:44:19 -07:00
schedule = coalesce(each.value.schedule, var.schedule)
2023-07-12 23:54:48 -07:00
concurrency_policy = "Replace"
starting_deadline_seconds = 60
suspend = lookup(each.value, "suspend", false)
job_template {
metadata {}
spec {
template {
metadata {}
spec {
restart_policy = "Never"
container {
name = "scrape"
image = each.value.image
image_pull_policy = "Always"
env {
name = "RSSCRAPE_PLAYER_NAME"
value = each.key
}
env {
name = "RSSCRAPE_INFLUX_URL"
value = var.influx_url
}
env {
name = "RSSCRAPE_TIMEOUT"
value = "60"
}
env {
name = "RSSCRAPE_PLAYER_ALIAS"
2023-07-13 23:44:19 -07:00
value = coalesce(each.value.alias, each.key)
2023-07-12 23:54:48 -07:00
}
dynamic "env" {
for_each = each.value.dryrun ? [1] : []
content {
name = "RSSCRAPE_DRYRUN"
value = 1
}
}
}
}
}
}
}
}
}