From 7d89f2a56fad9fb2dc5b398dcb72113a01bc68c1 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Thu, 7 Sep 2023 14:54:27 +0000 Subject: [PATCH] Initial commit --- code-server/main.tf | 41 +++++++++++++++++++++++++++++++++++++++++ personalize/main.tf | 31 +++++++++++++++++++++++++++++++ personalize/run.sh | 23 +++++++++++++++++++++++ vscode/main.tf | 30 ++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 code-server/main.tf create mode 100644 personalize/main.tf create mode 100644 personalize/run.sh create mode 100644 vscode/main.tf diff --git a/code-server/main.tf b/code-server/main.tf new file mode 100644 index 0000000..b886e8f --- /dev/null +++ b/code-server/main.tf @@ -0,0 +1,41 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + aws = { + source = "coder/coder" + version = ">= 0.11" + } + } +} + +variable "agent_id" { + type = string + description = "The ID of a Coder agent." +} + +variable "extensions" { + type = list(string) + description = "A list of extensions to install." +} + +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." +} + +data "http" "code-server-install" { + url = "https://raw.githubusercontent.com/coder/code-server/main/install.sh" +} + +resource "coder_script" "code-server" { + agent_id = var.agent_id + script = data.http.code-server-install.body + run_on_start = true +} diff --git a/personalize/main.tf b/personalize/main.tf new file mode 100644 index 0000000..633ddb1 --- /dev/null +++ b/personalize/main.tf @@ -0,0 +1,31 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + coder = { + source = "terraform.local/coder/coder" + version = ">= 0.12" + } + } +} + +variable "agent_id" { + type = string + description = "The ID of a Coder agent." +} + +variable "path" { + type = string + description = "The path to a script that will be ran on start enabling a user to personalize their workspace." + default = "~/personalize" +} + +resource "coder_script" "personalize" { + agent_id = var.agent_id + source = templatefile("run.sh", { + path: var.path, + }) + display_name = "Personalize" + icon = "/emojis/1f58c.png" + run_on_start = true +} diff --git a/personalize/run.sh b/personalize/run.sh new file mode 100644 index 0000000..d4470a1 --- /dev/null +++ b/personalize/run.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env sh + +PERSONALIZE_PATH=${path} + +# If the personalize script doesn't exist, educate +# the user how they can customize their environment! +if [ ! -f ${PERSONALIZE_PATH}/personalize.sh ]; then + echo "✨ You don't have a personalize script!" + echo "Run \`touch ${PERSONALIZE_PATH}\` to create one." + echo "Developers typically install their favorite packages here that may not be included in the base image." + exit 0 +fi + +# Check if the personalize script is executable, if not, +# try to make it executable and educate the user if it fails. +if [ ! -x ${PERSONALIZE_PATH}/personalize.sh ]; then + echo "🔐 Your personalize script isn't executable!" + echo "Run \`chmod +x ${PERSONALIZE_PATH}\` to make it executable." + exit 0 +fi + +# Run the personalize script! +exec $PERSONALIZE_PATH diff --git a/vscode/main.tf b/vscode/main.tf new file mode 100644 index 0000000..7434003 --- /dev/null +++ b/vscode/main.tf @@ -0,0 +1,30 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + aws = { + source = "coder/coder" + version = ">= 0.11" + } + } +} + +variable "agent_id" { + type = string + description = "The ID of a Coder agent." +} + +data "coder_workspace" "me" {} + +resource "coder_app" "vscode" { + agent_id = var.agent_id + external = true + url = join("", [ + "vscode://coder.coder-remote/open?owner=", + data.coder_workspace.me.owner, + "&workspace=", + data.coder_workspace.me.name, + "&token=", + data.coder_workspace.me.owner_session_token, + ]) +}