terraform { required_providers { coder = { source = "coder/coder" } incus = { source = "lxc/incus" } } } data "coder_provisioner" "me" {} provider "incus" {} data "coder_workspace" "me" {} data "coder_workspace_owner" "me" {} data "coder_parameter" "image" { name = "image" display_name = "Image" description = "The container image to use. Be sure to use a variant with cloud-init installed!" default = "ubuntu/jammy/cloud/amd64" icon = "/icon/image.svg" mutable = true } data "coder_parameter" "cpu" { name = "cpu" display_name = "CPU" description = "The number of CPUs to allocate to the workspace (1-8)" type = "number" default = "1" icon = "https://raw.githubusercontent.com/matifali/logos/main/cpu-3.svg" mutable = true validation { min = 1 max = 8 } } data "coder_parameter" "memory" { name = "memory" display_name = "Memory" description = "The amount of memory to allocate to the workspace in GB (up to 16GB)" type = "number" default = "2" icon = "/icon/memory.svg" mutable = true validation { min = 1 max = 16 } } data "coder_parameter" "git_repo" { type = "string" name = "Git repository" default = "https://github.com/coder/coder" description = "Clone a git repo into [base directory]" mutable = true } data "coder_parameter" "repo_base_dir" { type = "string" name = "Repository Base Directory" default = "~" description = "The directory specified will be created (if missing) and the specified repo will be cloned into [base directory]/{repo}🪄." mutable = true } resource "coder_agent" "main" { count = data.coder_workspace.me.start_count arch = data.coder_provisioner.me.arch os = "linux" dir = "/home/${local.workspace_user}" env = { CODER_WORKSPACE_ID = data.coder_workspace.me.id } metadata { display_name = "CPU Usage" key = "0_cpu_usage" script = "coder stat cpu" interval = 10 timeout = 1 } metadata { display_name = "RAM Usage" key = "1_ram_usage" script = "coder stat mem" interval = 10 timeout = 1 } metadata { display_name = "Home Disk" key = "3_home_disk" script = "coder stat disk --path /home/${lower(data.coder_workspace_owner.me.name)}" interval = 60 timeout = 1 } } module "git-clone" { source = "registry.coder.com/modules/git-clone/coder" version = "1.0.2" agent_id = local.agent_id url = data.coder_parameter.git_repo.value base_dir = local.repo_base_dir } module "code-server" { source = "registry.coder.com/modules/code-server/coder" version = "1.0.2" agent_id = local.agent_id folder = local.repo_base_dir } module "filebrowser" { source = "registry.coder.com/modules/filebrowser/coder" version = "1.0.2" agent_id = local.agent_id } module "coder-login" { source = "registry.coder.com/modules/coder-login/coder" version = "1.0.2" agent_id = local.agent_id } resource "incus_volume" "home" { name = "coder-${data.coder_workspace.me.id}-home" pool = local.pool } resource "incus_volume" "docker" { name = "coder-${data.coder_workspace.me.id}-docker" pool = local.pool } resource "incus_cached_image" "image" { source_remote = "images" source_image = data.coder_parameter.image.value } resource "incus_instance_file" "agent_token" { count = data.coder_workspace.me.start_count instance = incus_instance.dev.name content = <