tf/modules/swarm/spaceapi/main.tf

66 lines
1.6 KiB
HCL

data "docker_registry_image" "spaceapi" {
name = "git.chaoswest.tv/cwtv/spaceapi:latest"
}
data "docker_network" "traefik" {
name = "traefik"
}
locals {
labels = {
"shepherd.auto-update" = "true",
"traefik.enable" = "true"
"traefik.http.services.spaceapi.loadbalancer.server.port" = "8000",
"traefik.http.routers.spaceapi.rule" = "Host(`api.chaoswest.tv`)||Host(`api.montage2.de`)",
"traefik.http.routers.spaceapi.tls" = "true",
"traefik.http.routers.spaceapi.tls.certresolver" = "default",
}
}
resource "docker_service" "spaceapi" {
name = "spaceapi"
dynamic "labels" {
for_each = local.labels
content {
label = labels.key
value = labels.value
}
}
task_spec {
networks_advanced {
name = data.docker_network.traefik.id
}
container_spec {
image = "${data.docker_registry_image.spaceapi.name}@${data.docker_registry_image.spaceapi.sha256_digest}"
env = {
WORKERS = "12"
}
}
}
}
data "hetznerdns_zone" "montage2_de" {
name = "montage2.de"
}
resource "hetznerdns_record" "montage2_de" {
zone_id = data.hetznerdns_zone.montage2_de.id
name = "api"
value = "ax41-1.fsn.mon2.de."
type = "CNAME"
}
data "hetznerdns_zone" "chaoswest_tv" {
name = "chaoswest.tv"
}
resource "hetznerdns_record" "chaoswest_tv" {
zone_id = data.hetznerdns_zone.chaoswest_tv.id
name = "api"
value = "ax41-1.fsn.mon2.de."
type = "CNAME"
}