diff --git a/modules/swarm/spaceapi/main.tf b/modules/swarm/spaceapi/main.tf new file mode 100644 index 0000000..57be570 --- /dev/null +++ b/modules/swarm/spaceapi/main.tf @@ -0,0 +1,65 @@ +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" +} diff --git a/modules/swarm/spaceapi/outputs.tf b/modules/swarm/spaceapi/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/swarm/spaceapi/variables.tf b/modules/swarm/spaceapi/variables.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/swarm/spaceapi/version.tf b/modules/swarm/spaceapi/version.tf new file mode 100644 index 0000000..be1d72e --- /dev/null +++ b/modules/swarm/spaceapi/version.tf @@ -0,0 +1,13 @@ +terraform { + required_version = "1.5.5" + required_providers { + hetznerdns = { + source = "timohirt/hetznerdns" + version = "~>2.2" + } + docker = { + source = "kreuzwerker/docker" + version = "~>3.0" + } + } +} diff --git a/stacks/ax41-1/README.md b/stacks/ax41-1/README.md index d8a18ee..2267f45 100644 --- a/stacks/ax41-1/README.md +++ b/stacks/ax41-1/README.md @@ -25,6 +25,7 @@ | [jitsi](#module\_jitsi) | ../../modules/swarm/jitsi | n/a | | [shepherd](#module\_shepherd) | ../../modules/swarm/shepherd | n/a | | [shit](#module\_shit) | ../../modules/swarm/shit | n/a | +| [spaceapi](#module\_spaceapi) | ../../modules/swarm/spaceapi | n/a | | [traefik](#module\_traefik) | ../../modules/swarm/traefik | n/a | ## Resources diff --git a/stacks/ax41-1/main.tf b/stacks/ax41-1/main.tf index 646544c..9affe5a 100644 --- a/stacks/ax41-1/main.tf +++ b/stacks/ax41-1/main.tf @@ -30,6 +30,10 @@ module "shit" { source = "../../modules/swarm/shit" } +module "spaceapi" { + source = "../../modules/swarm/spaceapi" +} + module "forgejo" { source = "../../modules/swarm/forgejo" }