From 4e8919c1f445a3848dd9ef029672cc34610dab84 Mon Sep 17 00:00:00 2001 From: Layla Manley Date: Mon, 3 Jun 2024 19:39:30 +0200 Subject: [PATCH] Add shlink to Terraform --- services/shlink/Taskfile.dist.yml | 8 ++++++++ services/shlink/_common/main.tf | 28 ++++++++++++++++++++++++++++ services/shlink/_common/vars.tf | 10 ++++++++++ services/shlink/_common/versions.tf | 7 +++++++ services/shlink/main/main.tf | 6 ++++++ services/shlink/main/versions.tf | 7 +++++++ 6 files changed, 66 insertions(+) create mode 100644 services/shlink/Taskfile.dist.yml create mode 100644 services/shlink/_common/main.tf create mode 100644 services/shlink/_common/vars.tf create mode 100644 services/shlink/_common/versions.tf create mode 100644 services/shlink/main/main.tf create mode 100644 services/shlink/main/versions.tf diff --git a/services/shlink/Taskfile.dist.yml b/services/shlink/Taskfile.dist.yml new file mode 100644 index 0000000..99fef78 --- /dev/null +++ b/services/shlink/Taskfile.dist.yml @@ -0,0 +1,8 @@ +version: "3" + +includes: + tf: + vars: + SERVICE: "shlink" + ENVIRONMENT: "main" + taskfile: ../../taskfiles/Taskfile_service.dist.yml diff --git a/services/shlink/_common/main.tf b/services/shlink/_common/main.tf new file mode 100644 index 0000000..9a82dc6 --- /dev/null +++ b/services/shlink/_common/main.tf @@ -0,0 +1,28 @@ +data "vault_generic_secret" "geolite" { + path = "secret/services/shlink/geolite" +} + +resource "docker_container" "shlink" { + image = "shlinkio/shlink:${var.shlink_version}" + name = var.container_name + + restart = "always" + + env = [ + "IS_HTTPS_ENABLED=false", + "DEFAULT_DOMAIN=lnk.layla.gg", + "GEOLITE_LICENSE_KEY=${data.vault_generic_secret.geolite.data["license_key"]}", + ] + + ports { + internal = 8080 + external = 8602 + } + + mounts { + target = "/etc/shlink/data" + source = "/volume1/cloud/${var.container_name}/data" + read_only = false + type = "bind" + } +} diff --git a/services/shlink/_common/vars.tf b/services/shlink/_common/vars.tf new file mode 100644 index 0000000..e94067b --- /dev/null +++ b/services/shlink/_common/vars.tf @@ -0,0 +1,10 @@ +variable "shlink_version" { + description = "Container tag" + type = string + default = "1" +} + +variable "container_name" { + description = "Container name" + type = string +} diff --git a/services/shlink/_common/versions.tf b/services/shlink/_common/versions.tf new file mode 100644 index 0000000..b433ffb --- /dev/null +++ b/services/shlink/_common/versions.tf @@ -0,0 +1,7 @@ +terraform { + required_providers { + docker = { + source = "kreuzwerker/docker" + } + } +} diff --git a/services/shlink/main/main.tf b/services/shlink/main/main.tf new file mode 100644 index 0000000..3921c6f --- /dev/null +++ b/services/shlink/main/main.tf @@ -0,0 +1,6 @@ +module "shlink" { + source = "../_common" + + container_name = "shlink" + shlink_version = "latest" +} diff --git a/services/shlink/main/versions.tf b/services/shlink/main/versions.tf new file mode 100644 index 0000000..b433ffb --- /dev/null +++ b/services/shlink/main/versions.tf @@ -0,0 +1,7 @@ +terraform { + required_providers { + docker = { + source = "kreuzwerker/docker" + } + } +}