From c01ffa90f960a554846e03e89a32a0525ddaf86a Mon Sep 17 00:00:00 2001 From: dd84ai Date: Mon, 4 Mar 2024 00:21:26 +0100 Subject: [PATCH] refactor: prepare for migration to kube --- .../tf/modules/darkbot/{main.tf => docker.tf} | 26 +++-------------- infra/tf/modules/darkbot/input.tf | 29 +++++++++++++++++++ infra/tf/modules/darkbot/kube.tf | 0 infra/tf/production/main.tf | 3 +- infra/tf/staging/main.tf | 1 + 5 files changed, 36 insertions(+), 23 deletions(-) rename infra/tf/modules/darkbot/{main.tf => docker.tf} (78%) create mode 100644 infra/tf/modules/darkbot/input.tf create mode 100644 infra/tf/modules/darkbot/kube.tf diff --git a/infra/tf/modules/darkbot/main.tf b/infra/tf/modules/darkbot/docker.tf similarity index 78% rename from infra/tf/modules/darkbot/main.tf rename to infra/tf/modules/darkbot/docker.tf index ee1036b5..d096ac6b 100644 --- a/infra/tf/modules/darkbot/main.tf +++ b/infra/tf/modules/darkbot/docker.tf @@ -1,36 +1,18 @@ # Create a docker image resource # -> docker pull nginx:latest resource "docker_image" "darkbot" { + count = var.mode == "docker" ? 1 : 0 name = "darkwind8/darkbot:${var.tag_version}" keep_locally = true } -variable "tag_version" { - type = string -} - -variable "configurator_dbname" { - type = string -} - -variable "consoler_prefix" { - type = string -} - -variable "debug" { - type = bool - default = false -} - -variable "secrets" { - type = map(string) -} - # # Create a docker container resource # # -> same as 'docker run --name nginx -p8080:80 -d nginx:latest' resource "docker_container" "darkbot" { + count = var.mode == "docker" ? 1 : 0 + name = "darkbot" - image = docker_image.darkbot.image_id + image = docker_image.darkbot[0].image_id env = [ "SCRAPPY_PLAYER_URL=${var.secrets["SCRAPPY_PLAYER_URL"]}", diff --git a/infra/tf/modules/darkbot/input.tf b/infra/tf/modules/darkbot/input.tf new file mode 100644 index 00000000..8a46787f --- /dev/null +++ b/infra/tf/modules/darkbot/input.tf @@ -0,0 +1,29 @@ +variable "tag_version" { + type = string +} + +variable "configurator_dbname" { + type = string +} + +variable "consoler_prefix" { + type = string +} + +variable "debug" { + type = bool + default = false +} + +variable "secrets" { + type = map(string) +} + +variable "mode" { + type = string + + validation { + condition = contains(["kubernetes", "docker"], var.mode) + error_message = "Valid mode. should be docker or kubernetes" + } +} diff --git a/infra/tf/modules/darkbot/kube.tf b/infra/tf/modules/darkbot/kube.tf new file mode 100644 index 00000000..e69de29b diff --git a/infra/tf/production/main.tf b/infra/tf/production/main.tf index bd6ea264..6ad0e46f 100644 --- a/infra/tf/production/main.tf +++ b/infra/tf/production/main.tf @@ -21,7 +21,7 @@ locals { } provider "docker" { - host = "ssh://root@${module.stack.cluster_ip}:22" + host = "ssh://root@${module.stack.ipv4_address}:22" ssh_opts = ["-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-i", "~/.ssh/id_rsa.darklab"] } @@ -31,4 +31,5 @@ module "darkbot" { consoler_prefix = "." secrets = local.secrets tag_version = "v1.5.1" + mode = "docker" } \ No newline at end of file diff --git a/infra/tf/staging/main.tf b/infra/tf/staging/main.tf index aed96ba5..56d65914 100644 --- a/infra/tf/staging/main.tf +++ b/infra/tf/staging/main.tf @@ -23,4 +23,5 @@ module "darkbot" { secrets = local.secrets tag_version = "v1.5.1-arm" debug = false + mode = "docker" }