From 9b9dd76e1e3a4f9aa6c0b4f575a0564bd82c6c16 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 21 Sep 2023 11:49:37 +0300 Subject: [PATCH] wip --- kasmvnc/main.tf | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ kasmvnc/run.sh | 38 +++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 kasmvnc/main.tf create mode 100644 kasmvnc/run.sh diff --git a/kasmvnc/main.tf b/kasmvnc/main.tf new file mode 100644 index 0000000..65ea242 --- /dev/null +++ b/kasmvnc/main.tf @@ -0,0 +1,82 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + coder = { + source = "coder/coder" + version = ">= 0.12" + } + } +} + +variable "agent_id" { + type = string + description = "The ID of a Coder agent." +} + +variable "extensions" { + type = list(string) + description = "A list of extensions to install." + default = [] +} + +variable "port" { + type = number + description = "The port to run code-server on." + default = 13337 +} + +variable "settings" { + type = map(string) + description = "A map of settings to apply to code-server." + default = {} +} + +variable "folder" { + type = string + description = "The folder to open in code-server." + default = "" +} + +variable "install_prefix" { + type = string + description = "The prefix to install code-server to." + default = "/tmp/code-server" +} + +variable "log_path" { + type = string + description = "The path to log code-server to." + default = "/tmp/code-server.log" +} + +resource "coder_script" "code-server" { + agent_id = var.agent_id + display_name = "code-server" + icon = "/icon/code.svg" + script = templatefile("${path.module}/run.sh", { + EXTENSIONS : join(",", var.extensions), + PORT : var.port, + LOG_PATH : var.log_path, + INSTALL_PREFIX : var.install_prefix, + // This is necessary otherwise the quotes are stripped! + SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""), + }) + run_on_start = true +} + +resource "coder_app" "kasm_vnc" { + agent_id = var.agent_id + slug = "kasm-vnc" + display_name = "kasmVNC" + url = "http://localhost:${var.port}" + icon = "/icon/vnc.svg" + subdomain = false + share = "owner" + + healthcheck { + url = "http://localhost:${var.port}/healthz" + interval = 5 + threshold = 6 + } +} diff --git a/kasmvnc/run.sh b/kasmvnc/run.sh new file mode 100644 index 0000000..49347f9 --- /dev/null +++ b/kasmvnc/run.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Check if LXDE is installed +if ! dpkg -s lxde &>/dev/null; then + sudo apt-get update + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y lxde +else + echo "LXDE is already installed." +fi + +# Check if vncserver is installed +if ! dpkg -s kasmvncserver &>/dev/null; then + cd /tmp + wget https://github.com/kasmtech/KasmVNC/releases/download/v1.1.0/kasmvncserver_focal_1.1.0_amd64.deb + sudo apt install -y ./kasmvncserver_focal_1.1.0_amd64.deb +else + echo "VNC Server is already installed." +fi + +sudo addgroup $USER ssl-cert + +# Coder port-forwarding from dashboard only supports HTTP +sudo bash -c 'cat > /etc/kasmvnc/kasmvnc.yaml <