diff --git a/vs-code-server/template/main.tf b/vs-code-server/template/main.tf index 983c299..16066d6 100644 --- a/vs-code-server/template/main.tf +++ b/vs-code-server/template/main.tf @@ -1,60 +1,211 @@ -# main.tf (無 Docker provider 版,單容器 VSCode) terraform { required_providers { coder = { source = "coder/coder" } + docker = { + source = "kreuzwerker/docker" + } } } -provider "coder" {} +locals { + username = data.coder_workspace_owner.me.name +} -# 基本 workspace 資料 +variable "docker_socket" { + default = "" + description = "(Optional) Docker socket URI" + type = string +} + +provider "docker" { + # Defaulting to null if the variable is an empty string lets us have an optional variable without having to set our own default + host = var.docker_socket != "" ? var.docker_socket : null +} + +data "coder_provisioner" "me" {} data "coder_workspace" "me" {} - -# 取得使用者名稱 data "coder_workspace_owner" "me" {} -# 自動建立使用者 config 目錄與預設設定(使用 dir,無 shell) resource "coder_agent" "main" { - os = "linux" - arch = "amd64" + arch = data.coder_provisioner.me.arch + os = "linux" + startup_script = <<-EOT + set -e - dir = "/projects/${data.coder_workspace_owner.me.name}" + # Prepare user home with default files on first start. + if [ ! -f ~/.init_done ]; then + cp -rT /etc/skel ~ + touch ~/.init_done + fi - # 預設 VSCode 設定檔 + # Add any commands that should be executed at workspace startup (e.g install requirements, start a program, etc) here + EOT + + # These environment variables allow you to make Git commits right away after creating a + # workspace. Note that they take precedence over configuration defined in ~/.gitconfig! + # You can remove this block if you'd prefer to configure Git manually or using + # dotfiles. (see docs/dotfiles.md) env = { - CODE_SERVER_CONFIG = <