add VS Code Web module (#25)
							parent
							
								
									616443d2f4
								
							
						
					
					
						commit
						06f7dd5dcd
					
				@ -0,0 +1,36 @@
 | 
			
		||||
---
 | 
			
		||||
display_name: vscode-web
 | 
			
		||||
description: VS Code Web - Visual Studio Code in the browser
 | 
			
		||||
icon: ../.icons/code.svg
 | 
			
		||||
maintainer_github: coder
 | 
			
		||||
verified: true
 | 
			
		||||
tags: [helper, ide, vscode, web]
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
# VS Code Web
 | 
			
		||||
 | 
			
		||||
Automatically install [VS Code](https://code.visualstudio.com) in a workspace, create an app to access it via the dashboard.
 | 
			
		||||
 | 
			
		||||
## Examples
 | 
			
		||||
 | 
			
		||||
1. Install VS Code Web with default settings:
 | 
			
		||||
 | 
			
		||||
   ```hcl
 | 
			
		||||
   module "vscode-web" {
 | 
			
		||||
       source         = "https://registry.coder.com/modules/vscode-web"
 | 
			
		||||
       agent_id       = coder_agent.example.id
 | 
			
		||||
       accept_license = true
 | 
			
		||||
   }
 | 
			
		||||
   ```
 | 
			
		||||
 | 
			
		||||
2. Install VS Code Web with custom version and folder
 | 
			
		||||
 | 
			
		||||
   ```hcl
 | 
			
		||||
   module "vscode-web" {
 | 
			
		||||
       source         = "https://registry.coder.com/modules/vscode-web"
 | 
			
		||||
       agent_id       = coder_agent.example.id
 | 
			
		||||
       version        = "1.82.0"
 | 
			
		||||
       folder         = "/home/coder/my-projet"
 | 
			
		||||
       acept_license  = true
 | 
			
		||||
   }
 | 
			
		||||
   ```
 | 
			
		||||
@ -0,0 +1,82 @@
 | 
			
		||||
terraform {
 | 
			
		||||
  required_version = ">= 1.0"
 | 
			
		||||
 | 
			
		||||
  required_providers {
 | 
			
		||||
    coder = {
 | 
			
		||||
      source  = "coder/coder"
 | 
			
		||||
      version = ">= 0.12"
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "agent_id" {
 | 
			
		||||
  type        = string
 | 
			
		||||
  description = "The ID of a Coder agent."
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "port" {
 | 
			
		||||
  type        = number
 | 
			
		||||
  description = "The port to run VS Code Wbe on."
 | 
			
		||||
  default     = 13338
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "folder" {
 | 
			
		||||
  type        = string
 | 
			
		||||
  description = "The folder to open in VS Code Web."
 | 
			
		||||
  default     = ""
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "log_path" {
 | 
			
		||||
  type        = string
 | 
			
		||||
  description = "The path to log."
 | 
			
		||||
  default     = "/tmp/vscode-web.log"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "accept_license" {
 | 
			
		||||
  type        = bool
 | 
			
		||||
  description = "Accept the VS Code license. https://code.visualstudio.com/license"
 | 
			
		||||
  default     = false
 | 
			
		||||
  validation {
 | 
			
		||||
    condition     = var.accept_license == true
 | 
			
		||||
    error_message = "You must accept the VS Code license agreement by setting accept_license=true."
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "version" {
 | 
			
		||||
  type        = string
 | 
			
		||||
  description = "The version of VS Code to install."
 | 
			
		||||
  default     = "latest"
 | 
			
		||||
  # add a validation block to validate the version is greater than or equal to 1.82.0
 | 
			
		||||
  validation {
 | 
			
		||||
    condition     = var.version >= "1.82.0"
 | 
			
		||||
    error_message = "Version must be greater than or equal to 1.82.0"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
resource "coder_script" "vscode-web" {
 | 
			
		||||
  agent_id     = var.agent_id
 | 
			
		||||
  display_name = "VS Code Web"
 | 
			
		||||
  icon         = "/icon/code.svg"
 | 
			
		||||
  script = templatefile("${path.module}/run.sh", {
 | 
			
		||||
    PORT : var.port,
 | 
			
		||||
    LOG_PATH : var.log_path,
 | 
			
		||||
    VERSION : var.version,
 | 
			
		||||
  })
 | 
			
		||||
  run_on_start = true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
resource "coder_app" "vscode-web" {
 | 
			
		||||
  agent_id     = var.agent_id
 | 
			
		||||
  slug         = "vscode-web"
 | 
			
		||||
  display_name = "VS Code Web"
 | 
			
		||||
  url          = "http://localhost:${var.port}/?folder=${var.folder}"
 | 
			
		||||
  icon         = "/icon/code.svg"
 | 
			
		||||
  subdomain    = true
 | 
			
		||||
  share        = "owner"
 | 
			
		||||
 | 
			
		||||
  healthcheck {
 | 
			
		||||
    url       = "http://localhost:${var.port}/healthz"
 | 
			
		||||
    interval  = 5
 | 
			
		||||
    threshold = 6
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,15 @@
 | 
			
		||||
#!/usr/bin/env sh
 | 
			
		||||
 | 
			
		||||
BOLD='\033[0;1m'
 | 
			
		||||
# check if
 | 
			
		||||
printf "$${BOLD}Installing VS Code!\n"
 | 
			
		||||
output=$(curl -L "https://update.code.visualstudio.com/${VERSION}/linux-deb-x64/stable" -o /tmp/code.deb && sudo dpkg -i /tmp/code.deb && sudo apt-get install -f -y)
 | 
			
		||||
if [ $? -ne 0 ]; then
 | 
			
		||||
  echo "Failed to install VS Code: $output"
 | 
			
		||||
  exit 1
 | 
			
		||||
fi
 | 
			
		||||
printf "🥳 VS code has been installed.\n\n"
 | 
			
		||||
 | 
			
		||||
echo "👷 Running code serve-web in the background..."
 | 
			
		||||
echo "Check logs at ${LOG_PATH}!"
 | 
			
		||||
code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms >${LOG_PATH} 2>&1 &
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue