Skip to content

Commit f712d1c

Browse files
authored
feat: add template for externally managed workspaces to coder-labs (#343)
## Description Add externally-managed-workspace template for connecting Coder workspaces to externally provisioned compute resources ## Type of Change - [ ] New module - [ ] Bug fix - [x] Feature/enhancement - [ ] Documentation - [ ] Other ## Testing & Validation - [x] Tests pass (`bun test`) - [x] Code formatted (`bun run fmt`) - [x] Changes tested locally ## Related Issues coder/coder#19091
1 parent bc383a3 commit f712d1c

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

.icons/electric-plug-emoji.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
display_name: Externally Managed Workspace
3+
description: A template to provision externally managed resources as Coder workspaces
4+
icon: ../../../../.icons/electric-plug-emoji.svg
5+
verified: true
6+
tags: [external]
7+
---
8+
9+
# Externally Managed Workspace Template
10+
11+
This template provides a minimal scaffolding for creating Coder workspaces that connect to externally provisioned compute resources.
12+
13+
Use this template as a starting point to build your own custom templates for scenarios where you need to connect to existing infrastructure.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
version = ">= 2.10"
6+
}
7+
}
8+
}
9+
10+
data "coder_parameter" "agent_config" {
11+
name = "agent_config"
12+
display_name = "Agent Configuration"
13+
description = "Select the operating system and architecture combination for the agent"
14+
type = "string"
15+
default = "linux-amd64"
16+
17+
option {
18+
name = "Linux AMD64"
19+
value = "linux-amd64"
20+
}
21+
option {
22+
name = "Linux ARM64"
23+
value = "linux-arm64"
24+
}
25+
option {
26+
name = "Linux ARMv7"
27+
value = "linux-armv7"
28+
}
29+
option {
30+
name = "Windows AMD64"
31+
value = "windows-amd64"
32+
}
33+
option {
34+
name = "Windows ARM64"
35+
value = "windows-arm64"
36+
}
37+
option {
38+
name = "macOS AMD64"
39+
value = "darwin-amd64"
40+
}
41+
option {
42+
name = "macOS ARM64 (Apple Silicon)"
43+
value = "darwin-arm64"
44+
}
45+
}
46+
47+
data "coder_workspace" "me" {}
48+
49+
locals {
50+
agent_config = split("-", data.coder_parameter.agent_config.value)
51+
agent_os = local.agent_config[0]
52+
agent_arch = local.agent_config[1]
53+
}
54+
55+
resource "coder_agent" "main" {
56+
arch = local.agent_arch
57+
os = local.agent_os
58+
}
59+
60+
resource "coder_external_agent" "main" {
61+
agent_id = coder_agent.main.id
62+
}
63+
64+
# Adds code-server
65+
# See all available modules at https://registry.coder.com/modules
66+
module "code-server" {
67+
count = data.coder_workspace.me.start_count
68+
source = "registry.coder.com/coder/code-server/coder"
69+
70+
# 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.
71+
version = "~> 1.0"
72+
73+
agent_id = coder_agent.main.id
74+
}

0 commit comments

Comments
 (0)