From 62235696b5db73be917ce7304a98f88323097a6e Mon Sep 17 00:00:00 2001 From: Kacper Sawicki Date: Tue, 19 Aug 2025 12:41:50 +0000 Subject: [PATCH 1/3] feat: add template for externally managed workspaces to coder-labs --- .icons/paperclip-emoji.svg | 1 + .../externally-managed-workspace/README.md | 13 ++++++++ .../externally-managed-workspace/main.tf | 30 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 .icons/paperclip-emoji.svg create mode 100644 registry/coder-labs/templates/externally-managed-workspace/README.md create mode 100644 registry/coder-labs/templates/externally-managed-workspace/main.tf diff --git a/.icons/paperclip-emoji.svg b/.icons/paperclip-emoji.svg new file mode 100644 index 000000000..2f6ce42a9 --- /dev/null +++ b/.icons/paperclip-emoji.svg @@ -0,0 +1 @@ +📎 \ No newline at end of file diff --git a/registry/coder-labs/templates/externally-managed-workspace/README.md b/registry/coder-labs/templates/externally-managed-workspace/README.md new file mode 100644 index 000000000..afc3d9f5b --- /dev/null +++ b/registry/coder-labs/templates/externally-managed-workspace/README.md @@ -0,0 +1,13 @@ +--- +display_name: Externally Managed Workspace +description: A template for externally managed workspaces +icon: ../../../../.icons/paperclip-emoji.svg +verified: true +tags: [external] +--- + +# Externally Managed Workspace Template + +This template provides a minimal scaffolding for creating Coder workspaces that connect to externally provisioned compute resources. + +Use this template as a starting point to build your own custom templates for scenarios where you need to connect to existing infrastructure. diff --git a/registry/coder-labs/templates/externally-managed-workspace/main.tf b/registry/coder-labs/templates/externally-managed-workspace/main.tf new file mode 100644 index 000000000..b298e397d --- /dev/null +++ b/registry/coder-labs/templates/externally-managed-workspace/main.tf @@ -0,0 +1,30 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + } + } +} + +data "coder_workspace" "me" {} + +resource "coder_agent" "main" { + arch = "amd64" + os = "linux" +} + +resource "coder_external_agent" "main" { + agent_id = coder_agent.main.id +} + +# Adds code-server +# See all available modules at https://registry.coder.com/modules +module "code-server" { + count = data.coder_workspace.me.start_count + source = "registry.coder.com/coder/code-server/coder" + + # This ensures that the latest non-breaking version of the module gets downloaded, you can also pin the module version to prevent breaking changes in production. + version = "~> 1.0" + + agent_id = coder_agent.main.id +} \ No newline at end of file From 1d777ebf3fadd55b52d5e17e7ba8085721f5a66b Mon Sep 17 00:00:00 2001 From: Kacper Sawicki Date: Wed, 20 Aug 2025 08:13:24 +0000 Subject: [PATCH 2/3] Apply review suggestions, use coder_parameter for agent OS & ARCH --- ...clip-emoji.svg => electric-plug-emoji.svg} | 2 +- .../externally-managed-workspace/README.md | 4 +- .../externally-managed-workspace/main.tf | 48 ++++++++++++++++++- 3 files changed, 49 insertions(+), 5 deletions(-) rename .icons/{paperclip-emoji.svg => electric-plug-emoji.svg} (77%) diff --git a/.icons/paperclip-emoji.svg b/.icons/electric-plug-emoji.svg similarity index 77% rename from .icons/paperclip-emoji.svg rename to .icons/electric-plug-emoji.svg index 2f6ce42a9..157438226 100644 --- a/.icons/paperclip-emoji.svg +++ b/.icons/electric-plug-emoji.svg @@ -1 +1 @@ -📎 \ No newline at end of file +🔌 \ No newline at end of file diff --git a/registry/coder-labs/templates/externally-managed-workspace/README.md b/registry/coder-labs/templates/externally-managed-workspace/README.md index afc3d9f5b..661349eb0 100644 --- a/registry/coder-labs/templates/externally-managed-workspace/README.md +++ b/registry/coder-labs/templates/externally-managed-workspace/README.md @@ -1,7 +1,7 @@ --- display_name: Externally Managed Workspace -description: A template for externally managed workspaces -icon: ../../../../.icons/paperclip-emoji.svg +description: A template to provision externally managed resources as Coder workspaces +icon: ../../../../.icons/electric-plug-emoji.svg verified: true tags: [external] --- diff --git a/registry/coder-labs/templates/externally-managed-workspace/main.tf b/registry/coder-labs/templates/externally-managed-workspace/main.tf index b298e397d..9144ae779 100644 --- a/registry/coder-labs/templates/externally-managed-workspace/main.tf +++ b/registry/coder-labs/templates/externally-managed-workspace/main.tf @@ -2,15 +2,59 @@ terraform { required_providers { coder = { source = "coder/coder" + version = ">= 2.10" } } } +data "coder_parameter" "agent_config" { + name = "agent_config" + display_name = "Agent Configuration" + description = "Select the operating system and architecture combination for the agent" + type = "string" + default = "linux-amd64" + + option { + name = "Linux AMD64" + value = "linux-amd64" + } + option { + name = "Linux ARM64" + value = "linux-arm64" + } + option { + name = "Linux ARMv7" + value = "linux-armv7" + } + option { + name = "Windows AMD64" + value = "windows-amd64" + } + option { + name = "Windows ARM64" + value = "windows-arm64" + } + option { + name = "macOS AMD64" + value = "darwin-amd64" + } + option { + name = "macOS ARM64 (Apple Silicon)" + value = "darwin-arm64" + } +} + data "coder_workspace" "me" {} +locals { + agent_config = split("-", data.coder_parameter.agent_config.value) + agent_os = local.agent_config[0] + agent_arch = local.agent_config[1] +} + resource "coder_agent" "main" { - arch = "amd64" - os = "linux" + arch = local.agent_arch + os = local.agent_os } resource "coder_external_agent" "main" { From 87dc79d9a6a8edddc7d0babdcb4aafecd1468f47 Mon Sep 17 00:00:00 2001 From: Kacper Sawicki Date: Wed, 20 Aug 2025 08:20:56 +0000 Subject: [PATCH 3/3] Fix fmt --- .../externally-managed-workspace/main.tf | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/registry/coder-labs/templates/externally-managed-workspace/main.tf b/registry/coder-labs/templates/externally-managed-workspace/main.tf index 9144ae779..d80816fca 100644 --- a/registry/coder-labs/templates/externally-managed-workspace/main.tf +++ b/registry/coder-labs/templates/externally-managed-workspace/main.tf @@ -1,45 +1,45 @@ terraform { required_providers { coder = { - source = "coder/coder" + source = "coder/coder" version = ">= 2.10" } } } data "coder_parameter" "agent_config" { - name = "agent_config" + name = "agent_config" display_name = "Agent Configuration" - description = "Select the operating system and architecture combination for the agent" - type = "string" - default = "linux-amd64" - + description = "Select the operating system and architecture combination for the agent" + type = "string" + default = "linux-amd64" + option { - name = "Linux AMD64" + name = "Linux AMD64" value = "linux-amd64" } option { - name = "Linux ARM64" + name = "Linux ARM64" value = "linux-arm64" } option { - name = "Linux ARMv7" + name = "Linux ARMv7" value = "linux-armv7" } option { - name = "Windows AMD64" + name = "Windows AMD64" value = "windows-amd64" } option { - name = "Windows ARM64" + name = "Windows ARM64" value = "windows-arm64" } option { - name = "macOS AMD64" + name = "macOS AMD64" value = "darwin-amd64" } option { - name = "macOS ARM64 (Apple Silicon)" + name = "macOS ARM64 (Apple Silicon)" value = "darwin-arm64" } }