diff --git a/main.tf b/main.tf index 2225661..50d99c6 100644 --- a/main.tf +++ b/main.tf @@ -1,13 +1,12 @@ terraform { backend "local" {} - required_version = ">= 0.13" + required_version = ">= 1.5" required_providers { kubernetes = { source = "hashicorp/kubernetes" version = "2.3.2" } } - experiments = [module_variable_optional_attrs] } @@ -20,9 +19,9 @@ provider "kubernetes" { variable "players" { type = map(object({ alias = optional(string) - suspend = optional(bool) - image = optional(string) - dryrun = optional(bool) + suspend = optional(bool, false) + image = optional(string, "dockermirror:5000/dpedu/rsscrape") + dryrun = optional(bool, false) schedule = optional(string) })) description = "players to scrape" @@ -45,35 +44,15 @@ variable "schedule" { } -locals { - players = { - for name, player in defaults( - var.players, - { - suspend = false - image = "dockermirror:5000/dpedu/rsscrape" - dryrun = false - schedule = var.schedule - } - ) : name => merge( - player, - { - label = coalesce(lookup(player, "alias", null), name) - } - ) - } -} - - resource "kubernetes_cron_job" "scraper" { - for_each = local.players + for_each = var.players metadata { - name = "rsscrape-${lower(replace(replace(each.value.label, " ", "-"), "_", "-"))}" + name = "rsscrape-${lower(replace(replace(each.key, " ", "-"), "_", "-"))}" namespace = var.namespace } spec { - schedule = each.value.schedule + schedule = coalesce(each.value.schedule, var.schedule) concurrency_policy = "Replace" starting_deadline_seconds = 60 suspend = lookup(each.value, "suspend", false) @@ -102,7 +81,7 @@ resource "kubernetes_cron_job" "scraper" { } env { name = "RSSCRAPE_PLAYER_ALIAS" - value = each.value.label + value = coalesce(each.value.alias, each.key) } dynamic "env" { for_each = each.value.dryrun ? [1] : []