diff --git a/registry/coder/modules/vscode-web/README.md b/registry/coder/modules/vscode-web/README.md index 47457857..9e5a5933 100644 --- a/registry/coder/modules/vscode-web/README.md +++ b/registry/coder/modules/vscode-web/README.md @@ -14,7 +14,7 @@ Automatically install [Visual Studio Code Server](https://code.visualstudio.com/ module "vscode-web" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/vscode-web/coder" - version = "1.3.1" + version = "1.3.2" agent_id = coder_agent.example.id accept_license = true } @@ -38,6 +38,19 @@ module "vscode-web" { } ``` +### Open a VS Code workspace file + +```tf +module "vscode-web" { + count = data.coder_workspace.me.start_count + source = "registry.coder.com/coder/vscode-web/coder" + version = "1.3.2" + agent_id = coder_agent.example.id + workspace = "/home/coder/project.code-workspace" + accept_license = true +} +``` + ### Install Extensions ```tf @@ -82,4 +95,3 @@ module "vscode-web" { commit_id = "e54c774e0add60467559eb0d1e229c6452cf8447" accept_license = true } -``` diff --git a/registry/coder/modules/vscode-web/main.tf b/registry/coder/modules/vscode-web/main.tf index c0072454..3912fa9f 100644 --- a/registry/coder/modules/vscode-web/main.tf +++ b/registry/coder/modules/vscode-web/main.tf @@ -34,7 +34,13 @@ variable "slug" { variable "folder" { type = string - description = "The folder to open in vscode-web." + description = "The folder to open in vscode-web. Cannot be used with 'workspace'." + default = "" +} + +variable "workspace" { + type = string + description = "Path to a .code-workspace file to open on startup. Cannot be used with 'folder'." default = "" } @@ -178,6 +184,7 @@ resource "coder_script" "vscode-web" { DISABLE_TRUST : var.disable_trust, EXTENSIONS_DIR : var.extensions_dir, FOLDER : var.folder, + WORKSPACE : var.workspace, AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions, SERVER_BASE_PATH : local.server_base_path, COMMIT_ID : var.commit_id, @@ -186,6 +193,11 @@ resource "coder_script" "vscode-web" { run_on_start = true lifecycle { + precondition { + condition = !(var.folder != "" && var.workspace != "") + error_message = "Cannot specify both 'folder' and 'workspace'. Please use only one." + } + precondition { condition = !var.offline || length(var.extensions) == 0 error_message = "Offline mode does not allow extensions to be installed" @@ -218,6 +230,11 @@ resource "coder_app" "vscode-web" { locals { server_base_path = var.subdomain ? "" : format("/@%s/%s/apps/%s/", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.slug) - url = var.folder == "" ? "http://localhost:${var.port}${local.server_base_path}" : "http://localhost:${var.port}${local.server_base_path}?folder=${var.folder}" - healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz" -} + + # Mutually exclusive: workspace takes precedence over folder + query_param = var.workspace != "" ? "workspace=${urlencode(var.workspace)}" : (var.folder != "" ? "folder=${urlencode(var.folder)}" : "") + + url = local.query_param != "" ? "http://localhost:${var.port}${local.server_base_path}?${local.query_param}" : "http://localhost:${var.port}${local.server_base_path}" + + healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz" +} \ No newline at end of file diff --git a/registry/coder/modules/vscode-web/run.sh b/registry/coder/modules/vscode-web/run.sh index 9346b4bd..e7e18db0 100644 --- a/registry/coder/modules/vscode-web/run.sh +++ b/registry/coder/modules/vscode-web/run.sh @@ -22,10 +22,18 @@ if [ "${DISABLE_TRUST}" = true ]; then DISABLE_TRUST_ARG="--disable-workspace-trust" fi +# Set workspace or folder argument +WORKSPACE_ARG="" +if [ -n "${WORKSPACE}" ]; then + WORKSPACE_ARG="${WORKSPACE}" +elif [ -n "${FOLDER}" ]; then + WORKSPACE_ARG="${FOLDER}" +fi + run_vscode_web() { - echo "👷 Running $VSCODE_WEB serve-local $EXTENSION_ARG $SERVER_BASE_PATH_ARG $DISABLE_TRUST_ARG --port ${PORT} --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} in the background..." + echo "👷 Running $VSCODE_WEB serve-local with workspace: ${WORKSPACE_ARG}" echo "Check logs at ${LOG_PATH}!" - "$VSCODE_WEB" serve-local "$EXTENSION_ARG" "$SERVER_BASE_PATH_ARG" "$DISABLE_TRUST_ARG" --port "${PORT}" --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 & + "$VSCODE_WEB" serve-local "$EXTENSION_ARG" "$SERVER_BASE_PATH_ARG" "$DISABLE_TRUST_ARG" --port "${PORT}" --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" "${WORKSPACE_ARG}" > "${LOG_PATH}" 2>&1 & } # Check if the settings file exists...