VS Code Web
By coder
VS Code Web - Visual Studio Code in the browser
accept_license
Default: falseAccept the VS Code Server license. https://code.visualstudio.com/license/server
agent_id
RequiredDefault: nullThe ID of a Coder agent.
auto_install_extensions
Default: falseAutomatically install recommended extensions when VS Code Web starts.
commit_id
Default: ""Specify the commit ID of the VS Code Web binary to pin to a specific version. If left empty, the latest stable version is used.
display_name
Default: "VS Code Web"The display name for the VS Code Web application.
extensions
Default: []A list of extensions to install.
extensions_dir
Default: ""Override the directory to store extensions in.
folder
Default: ""The folder to open in vscode-web.
install_prefix
Default: "/tmp/vscode-web"The prefix to install vscode-web to.
log_path
Default: "/tmp/vscode-web.log"The path to log.
offline
Default: falseJust run VS Code Web in the background, don't fetch it from the internet.
order
Default: nullThe order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order).
port
Default: 13338The port to run VS Code Web on.
settings
Default: {}A map of settings to apply to VS Code web.
share
Default: "owner"No description available
slug
Default: "vscode-web"The slug for the VS Code Web application.
subdomain
Default: trueDetermines whether the app will be accessed via it's own subdomain or whether it will be accessed via a path on Coder. If wildcards have not been setup by the administrator then apps with "subdomain" set to true will not be accessible.
telemetry_level
Default: "error"Set the telemetry level for VS Code Web.
use_cached
Default: falseUses cached copy of VS Code Web in the background, otherwise fetches it from internet.
1terraform {
2 required_version = ">= 1.0"
3
4 required_providers {
5 coder = {
6 source = "coder/coder"
7 version = ">= 0.17"
8 }
9 }
10}
11
12variable "agent_id" {
13 type = string
14 description = "The ID of a Coder agent."
15}
16
17variable "port" {
18 type = number
19 description = "The port to run VS Code Web on."
20 default = 13338
21}
22
23variable "display_name" {
24 type = string
25 description = "The display name for the VS Code Web application."
26 default = "VS Code Web"
27}
28
29variable "slug" {
30 type = string
31 description = "The slug for the VS Code Web application."
32 default = "vscode-web"
33}
34
35variable "folder" {
36 type = string
37 description = "The folder to open in vscode-web."
38 default = ""
39}
40
41variable "share" {
42 type = string
43 default = "owner"
44 validation {
45 condition = var.share == "owner" || var.share == "authenticated" || var.share == "public"
46 error_message = "Incorrect value. Please set either 'owner', 'authenticated', or 'public'."
47 }
48}
49
50variable "log_path" {
51 type = string
52 description = "The path to log."
53 default = "/tmp/vscode-web.log"
54}
55
56variable "install_prefix" {
57 type = string
58 description = "The prefix to install vscode-web to."
59 default = "/tmp/vscode-web"
60}
61
62variable "commit_id" {
63 type = string
64 description = "Specify the commit ID of the VS Code Web binary to pin to a specific version. If left empty, the latest stable version is used."
65 default = ""
66}
67
68variable "extensions" {
69 type = list(string)
70 description = "A list of extensions to install."
71 default = []
72}
73
74variable "accept_license" {
75 type = bool
76 description = "Accept the VS Code Server license. https://code.visualstudio.com/license/server"
77 default = false
78 validation {
79 condition = var.accept_license == true
80 error_message = "You must accept the VS Code license agreement by setting accept_license=true."
81 }
82}
83
84variable "telemetry_level" {
85 type = string
86 description = "Set the telemetry level for VS Code Web."
87 default = "error"
88 validation {
89 condition = var.telemetry_level == "off" || var.telemetry_level == "crash" || var.telemetry_level == "error" || var.telemetry_level == "all"
90 error_message = "Incorrect value. Please set either 'off', 'crash', 'error', or 'all'."
91 }
92}
93
94variable "order" {
95 type = number
96 description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)."
97 default = null
98}
99
100variable "settings" {
101 type = any
102 description = "A map of settings to apply to VS Code web."
103 default = {}
104}
105
106variable "offline" {
107 type = bool
108 description = "Just run VS Code Web in the background, don't fetch it from the internet."
109 default = false
110}
111
112variable "use_cached" {
113 type = bool
114 description = "Uses cached copy of VS Code Web in the background, otherwise fetches it from internet."
115 default = false
116}
117
118variable "extensions_dir" {
119 type = string
120 description = "Override the directory to store extensions in."
121 default = ""
122}
123
124variable "auto_install_extensions" {
125 type = bool
126 description = "Automatically install recommended extensions when VS Code Web starts."
127 default = false
128}
129
130variable "subdomain" {
131 type = bool
132 description = <<-EOT
133 Determines whether the app will be accessed via it's own subdomain or whether it will be accessed via a path on Coder.
134 If wildcards have not been setup by the administrator then apps with "subdomain" set to true will not be accessible.
135 EOT
136 default = true
137}
138
139data "coder_workspace_owner" "me" {}
140data "coder_workspace" "me" {}
141
142resource "coder_script" "vscode-web" {
143 agent_id = var.agent_id
144 display_name = "VS Code Web"
145 icon = "/icon/code.svg"
146 script = templatefile("${path.module}/run.sh", {
147 PORT : var.port,
148 LOG_PATH : var.log_path,
149 INSTALL_PREFIX : var.install_prefix,
150 EXTENSIONS : join(",", var.extensions),
151 TELEMETRY_LEVEL : var.telemetry_level,
152 // This is necessary otherwise the quotes are stripped!
153 SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""),
154 OFFLINE : var.offline,
155 USE_CACHED : var.use_cached,
156 EXTENSIONS_DIR : var.extensions_dir,
157 FOLDER : var.folder,
158 AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
159 SERVER_BASE_PATH : local.server_base_path,
160 COMMIT_ID : var.commit_id,
161 })
162 run_on_start = true
163
164 lifecycle {
165 precondition {
166 condition = !var.offline || length(var.extensions) == 0
167 error_message = "Offline mode does not allow extensions to be installed"
168 }
169
170 precondition {
171 condition = !var.offline || !var.use_cached
172 error_message = "Offline and Use Cached can not be used together"
173 }
174 }
175}
176
177resource "coder_app" "vscode-web" {
178 agent_id = var.agent_id
179 slug = var.slug
180 display_name = var.display_name
181 url = local.url
182 icon = "/icon/code.svg"
183 subdomain = var.subdomain
184 share = var.share
185 order = var.order
186
187 healthcheck {
188 url = local.healthcheck_url
189 interval = 5
190 threshold = 6
191 }
192}
193
194locals {
195 server_base_path = var.subdomain ? "" : format("/@%s/%s/apps/%s/", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.slug)
196 url = var.folder == "" ? "http://localhost:${var.port}${local.server_base_path}" : "http://localhost:${var.port}${local.server_base_path}?folder=${var.folder}"
197 healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz"
198}
199