mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: add agent metadata to example templates (#7044)
* add `display_name` * fix typos and `terraform validate` * update display_name * Add agent metadata * add % to cpu usage * update disk usage check script * remove metadata from containers and pods workspaces * removes disk metadata from container workspaces --------- Co-authored-by: Ben <me@bpmct.net>
This commit is contained in:
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
@@ -20,19 +20,21 @@ variable "ecs-cluster" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "cpu" {
|
||||
name = "cpu"
|
||||
description = "The number of CPU units to reserve for the container"
|
||||
type = "number"
|
||||
default = "1024"
|
||||
mutable = true
|
||||
name = "cpu"
|
||||
display_name = "CPU"
|
||||
description = "The number of CPU units to reserve for the container"
|
||||
type = "number"
|
||||
default = "1024"
|
||||
mutable = true
|
||||
}
|
||||
|
||||
data "coder_parameter" "memory" {
|
||||
name = "memory"
|
||||
description = "The amount of memory (in MiB) to allow the container to use"
|
||||
type = "number"
|
||||
default = "2048"
|
||||
mutable = true
|
||||
name = "memory"
|
||||
display_name = "Memory"
|
||||
description = "The amount of memory (in MiB) to allow the container to use"
|
||||
type = "number"
|
||||
default = "2048"
|
||||
mutable = true
|
||||
}
|
||||
|
||||
# configure AWS provider with creds present on Coder server host
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
@@ -14,10 +14,11 @@ terraform {
|
||||
# Last updated 2023-03-14
|
||||
# aws ec2 describe-regions | jq -r '[.Regions[].RegionName] | sort'
|
||||
data "coder_parameter" "region" {
|
||||
name = "Region"
|
||||
description = "The region to deploy the workspace in."
|
||||
default = "us-east-1"
|
||||
mutable = false
|
||||
name = "region"
|
||||
display_name = "Region"
|
||||
description = "The region to deploy the workspace in."
|
||||
default = "us-east-1"
|
||||
mutable = false
|
||||
option {
|
||||
name = "Asia Pacific (Tokyo)"
|
||||
value = "ap-northeast-1"
|
||||
@@ -106,10 +107,11 @@ data "coder_parameter" "region" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "instance_type" {
|
||||
name = "Instance Type"
|
||||
description = "What instance type should your workspace use?"
|
||||
default = "t3.micro"
|
||||
mutable = false
|
||||
name = "instance_type"
|
||||
display_name = "Instance Type"
|
||||
description = "What instance type should your workspace use?"
|
||||
default = "t3.micro"
|
||||
mutable = false
|
||||
option {
|
||||
name = "2 vCPU, 1 GiB RAM"
|
||||
value = "t3.micro"
|
||||
@@ -169,6 +171,40 @@ resource "coder_agent" "main" {
|
||||
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0
|
||||
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
|
||||
EOT
|
||||
|
||||
metadata {
|
||||
key = "cpu"
|
||||
display_name = "CPU Usage"
|
||||
interval = 5
|
||||
timeout = 5
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4 "%"}'
|
||||
EOT
|
||||
}
|
||||
metadata {
|
||||
key = "memory"
|
||||
display_name = "Memory Usage"
|
||||
interval = 5
|
||||
timeout = 5
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
free -m | awk 'NR==2{printf "%.2f%%\t", $3*100/$2 }'
|
||||
EOT
|
||||
}
|
||||
metadata {
|
||||
key = "disk"
|
||||
display_name = "Disk Usage"
|
||||
interval = 600 # every 10 minutes
|
||||
timeout = 30 # df can take a while on large filesystems
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
df /home/coder | awk '$NF=="/"{printf "%s", $5}'
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
resource "coder_app" "code-server" {
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
@@ -14,10 +14,11 @@ terraform {
|
||||
# Last updated 2023-03-14
|
||||
# aws ec2 describe-regions | jq -r '[.Regions[].RegionName] | sort'
|
||||
data "coder_parameter" "region" {
|
||||
name = "Region"
|
||||
description = "The region to deploy the workspace in."
|
||||
default = "us-east-1"
|
||||
mutable = false
|
||||
name = "region"
|
||||
display_name = "Region"
|
||||
description = "The region to deploy the workspace in."
|
||||
default = "us-east-1"
|
||||
mutable = false
|
||||
option {
|
||||
name = "Asia Pacific (Tokyo)"
|
||||
value = "ap-northeast-1"
|
||||
@@ -106,10 +107,11 @@ data "coder_parameter" "region" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "instance_type" {
|
||||
name = "Instance Type"
|
||||
description = "What instance type should your workspace use?"
|
||||
default = "t3.micro"
|
||||
mutable = false
|
||||
name = "instance_type"
|
||||
display_name = "Instance Type"
|
||||
description = "What instance type should your workspace use?"
|
||||
default = "t3.micro"
|
||||
mutable = false
|
||||
option {
|
||||
name = "2 vCPU, 1 GiB RAM"
|
||||
value = "t3.micro"
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
azurerm = {
|
||||
source = "hashicorp/azurerm"
|
||||
@@ -12,11 +12,12 @@ terraform {
|
||||
}
|
||||
|
||||
data "coder_parameter" "location" {
|
||||
name = "Location"
|
||||
description = "What location should your workspace live in?"
|
||||
default = "eastus"
|
||||
icon = "/emojis/1f310.png"
|
||||
mutable = false
|
||||
name = "location"
|
||||
display_name = "Location"
|
||||
description = "What location should your workspace live in?"
|
||||
default = "eastus"
|
||||
icon = "/emojis/1f310.png"
|
||||
mutable = false
|
||||
option {
|
||||
name = "US (Virginia)"
|
||||
value = "eastus"
|
||||
@@ -150,11 +151,12 @@ data "coder_parameter" "location" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "instance_type" {
|
||||
name = "Instance Type"
|
||||
description = "What instance type should your workspace use?"
|
||||
default = "Standard_B4ms"
|
||||
icon = "/icon/azure.png"
|
||||
mutable = false
|
||||
name = "instance_type"
|
||||
display_name = "Instance Type"
|
||||
description = "What instance type should your workspace use?"
|
||||
default = "Standard_B4ms"
|
||||
icon = "/icon/azure.png"
|
||||
mutable = false
|
||||
option {
|
||||
name = "Standard_B1ms (1 vCPU, 2 GiB RAM)"
|
||||
value = "Standard_B1ms"
|
||||
@@ -202,12 +204,13 @@ data "coder_parameter" "instance_type" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "home_size" {
|
||||
name = "Home Volume Size"
|
||||
description = "How large would you like your home volume to be (in GB)?"
|
||||
default = 20
|
||||
type = "number"
|
||||
icon = "/icon/azure.png"
|
||||
mutable = false
|
||||
name = "home_size"
|
||||
display_name = "Home Volume Size"
|
||||
description = "How large would you like your home volume to be (in GB)?"
|
||||
default = 20
|
||||
type = "number"
|
||||
icon = "/icon/azure.png"
|
||||
mutable = false
|
||||
validation {
|
||||
min = 1
|
||||
max = 1024
|
||||
@@ -226,6 +229,40 @@ resource "coder_agent" "main" {
|
||||
os = "linux"
|
||||
auth = "azure-instance-identity"
|
||||
login_before_ready = false
|
||||
|
||||
metadata {
|
||||
key = "cpu"
|
||||
display_name = "CPU Usage"
|
||||
interval = 5
|
||||
timeout = 5
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4 "%"}'
|
||||
EOT
|
||||
}
|
||||
metadata {
|
||||
key = "memory"
|
||||
display_name = "Memory Usage"
|
||||
interval = 5
|
||||
timeout = 5
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
free -m | awk 'NR==2{printf "%.2f%%\t", $3*100/$2 }'
|
||||
EOT
|
||||
}
|
||||
metadata {
|
||||
key = "disk"
|
||||
display_name = "Disk Usage"
|
||||
interval = 600 # every 10 minutes
|
||||
timeout = 30 # df can take a while on large filesystems
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
df /home/coder | awk '$NF=="/"{printf "%s", $5}'
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
locals {
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
digitalocean = {
|
||||
source = "digitalocean/digitalocean"
|
||||
@@ -52,10 +52,12 @@ variable "step2_do_admin_ssh_key" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "droplet_image" {
|
||||
name = "Which Droplet image would you like to use for your workspace?"
|
||||
default = "ubuntu-22-04-x64"
|
||||
type = "string"
|
||||
mutable = false
|
||||
name = "droplet_image"
|
||||
display_name = "Droplet Image"
|
||||
description = "Which Droplet image would you like to use?"
|
||||
default = "ubuntu-22-04-x64"
|
||||
type = "string"
|
||||
mutable = false
|
||||
option {
|
||||
name = "Ubuntu 22.04"
|
||||
value = "ubuntu-22-04-x64"
|
||||
@@ -109,11 +111,13 @@ data "coder_parameter" "droplet_image" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "droplet_size" {
|
||||
name = "Which Droplet configuration would you like to use?"
|
||||
default = "s-1vcpu-1gb"
|
||||
type = "string"
|
||||
icon = "/icon/memory.svg"
|
||||
mutable = false
|
||||
name = "droplet_size"
|
||||
display_name = "Droplet Size"
|
||||
description = "Which Droplet configuration would you like to use?"
|
||||
default = "s-1vcpu-1gb"
|
||||
type = "string"
|
||||
icon = "/icon/memory.svg"
|
||||
mutable = false
|
||||
option {
|
||||
name = "1 vCPU, 1 GB RAM"
|
||||
value = "s-1vcpu-1gb"
|
||||
@@ -142,11 +146,12 @@ data "coder_parameter" "droplet_size" {
|
||||
|
||||
|
||||
data "coder_parameter" "home_volume_size" {
|
||||
name = "How large would you like your home volume to be (in GB)?"
|
||||
description = "This volume will be mounted to /home/coder."
|
||||
type = "number"
|
||||
default = "20"
|
||||
mutable = false
|
||||
name = "home_volume_size"
|
||||
display_name = "Home Volume Size"
|
||||
description = "How large would you like your home volume to be (in GB)?"
|
||||
type = "number"
|
||||
default = "20"
|
||||
mutable = false
|
||||
validation {
|
||||
min = 1
|
||||
max = 999999
|
||||
@@ -154,12 +159,13 @@ data "coder_parameter" "home_volume_size" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "region" {
|
||||
name = "Which region would you like to use?"
|
||||
description = "This is the region where your workspace will be created."
|
||||
icon = "/emojis/1f30e.png"
|
||||
type = "string"
|
||||
default = "ams3"
|
||||
mutable = false
|
||||
name = "region"
|
||||
display_name = "Region"
|
||||
description = "This is the region where your workspace will be created."
|
||||
icon = "/emojis/1f30e.png"
|
||||
type = "string"
|
||||
default = "ams3"
|
||||
mutable = false
|
||||
option {
|
||||
name = "New York 1"
|
||||
value = "nyc1"
|
||||
@@ -240,6 +246,41 @@ resource "coder_agent" "main" {
|
||||
arch = "amd64"
|
||||
|
||||
login_before_ready = false
|
||||
|
||||
metadata {
|
||||
key = "cpu"
|
||||
display_name = "CPU Usage"
|
||||
interval = 5
|
||||
timeout = 5
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4 "%"}'
|
||||
EOT
|
||||
}
|
||||
metadata {
|
||||
key = "memory"
|
||||
display_name = "Memory Usage"
|
||||
interval = 5
|
||||
timeout = 5
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
free -m | awk 'NR==2{printf "%.2f%%\t", $3*100/$2 }'
|
||||
EOT
|
||||
}
|
||||
metadata {
|
||||
key = "disk"
|
||||
display_name = "Disk Usage"
|
||||
interval = 600 # every 10 minutes
|
||||
timeout = 30 # df can take a while on large filesystems
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
df /home/coder | awk '$NF=="/"{printf "%s", $5}'
|
||||
EOT
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
resource "digitalocean_volume" "home_volume" {
|
||||
|
||||
@@ -9,7 +9,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
docker = {
|
||||
source = "kreuzwerker/docker"
|
||||
@@ -28,24 +28,26 @@ data "coder_workspace" "me" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "docker_image" {
|
||||
name = "What Docker image would you like to use for your workspace?"
|
||||
description = "The Docker image will be used to build your workspace."
|
||||
default = "codercom/enterprise-base:ubuntu"
|
||||
icon = "/icon/docker.png"
|
||||
type = "string"
|
||||
mutable = false
|
||||
name = "docker_image"
|
||||
display_name = "Docker Image"
|
||||
description = "The Docker image will be used to build your workspace."
|
||||
default = "codercom/enterprise-base:ubuntu"
|
||||
icon = "/icon/docker.png"
|
||||
type = "string"
|
||||
mutable = false
|
||||
}
|
||||
|
||||
data "coder_parameter" "dotfiles_uri" {
|
||||
name = "What dotfiles repo would you like to use for your workspace?"
|
||||
description = <<-EOF
|
||||
name = "dotfiles_uri"
|
||||
display_name = "dotfiles URI"
|
||||
description = <<-EOF
|
||||
Dotfiles repo URI (optional)
|
||||
|
||||
see https://dotfiles.github.io
|
||||
EOF
|
||||
default = ""
|
||||
type = "string"
|
||||
mutable = true
|
||||
default = ""
|
||||
type = "string"
|
||||
mutable = true
|
||||
}
|
||||
|
||||
resource "coder_agent" "main" {
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
docker = {
|
||||
source = "kreuzwerker/docker"
|
||||
|
||||
@@ -6,7 +6,7 @@ terraform {
|
||||
}
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~>0.6.17"
|
||||
version = "~>0.7.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,19 +108,21 @@ EOF
|
||||
}
|
||||
|
||||
data "coder_parameter" "docker-image" {
|
||||
name = "Docker Image"
|
||||
description = "The docker image to use for the workspace"
|
||||
default = "codercom/code-server:latest"
|
||||
icon = "https://raw.githubusercontent.com/matifali/logos/main/docker.svg"
|
||||
name = "docker-image"
|
||||
display_name = "Docker Image"
|
||||
description = "The docker image to use for the workspace"
|
||||
default = "codercom/code-server:latest"
|
||||
icon = "https://raw.githubusercontent.com/matifali/logos/main/docker.svg"
|
||||
}
|
||||
|
||||
data "coder_parameter" "cpu" {
|
||||
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
|
||||
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
|
||||
@@ -128,11 +130,12 @@ data "coder_parameter" "cpu" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "cputype" {
|
||||
name = "CPU Type"
|
||||
description = "Which CPU type do you want?"
|
||||
default = "shared"
|
||||
icon = "https://raw.githubusercontent.com/matifali/logos/main/cpu-1.svg"
|
||||
mutable = true
|
||||
name = "cputype"
|
||||
display_name = "CPU Type"
|
||||
description = "Which CPU type do you want?"
|
||||
default = "shared"
|
||||
icon = "https://raw.githubusercontent.com/matifali/logos/main/cpu-1.svg"
|
||||
mutable = true
|
||||
option {
|
||||
name = "Shared"
|
||||
value = "shared"
|
||||
@@ -144,12 +147,13 @@ data "coder_parameter" "cputype" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "memory" {
|
||||
name = "Memory (GB)"
|
||||
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
|
||||
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 = data.coder_parameter.cputype.value == "performance" ? 2 : 1 # if the CPU type is performance, the minimum memory is 2GB
|
||||
max = 16
|
||||
@@ -157,11 +161,12 @@ data "coder_parameter" "memory" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "volume-size" {
|
||||
name = "Volume Size"
|
||||
description = "The size of the volume to create for the workspace in GB (1-20)"
|
||||
type = "number"
|
||||
default = "1"
|
||||
icon = "https://raw.githubusercontent.com/matifali/logos/main/database.svg"
|
||||
name = "volume-size"
|
||||
display_name = "Home Volume Size"
|
||||
description = "The size of the volume to create for the workspace in GB (1-20)"
|
||||
type = "number"
|
||||
default = "1"
|
||||
icon = "https://raw.githubusercontent.com/matifali/logos/main/database.svg"
|
||||
validation {
|
||||
min = 1
|
||||
max = 20
|
||||
@@ -170,10 +175,11 @@ data "coder_parameter" "volume-size" {
|
||||
|
||||
# You can see all available regions here: https://fly.io/docs/reference/regions/
|
||||
data "coder_parameter" "region" {
|
||||
name = "Region"
|
||||
description = "The region to deploy the workspace in"
|
||||
default = "ams"
|
||||
icon = "/emojis/1f30e.png"
|
||||
name = "region"
|
||||
display_name = "Region"
|
||||
description = "The region to deploy the workspace in"
|
||||
default = "ams"
|
||||
icon = "/emojis/1f30e.png"
|
||||
option {
|
||||
name = "Amsterdam, Netherlands"
|
||||
value = "ams"
|
||||
@@ -254,7 +260,7 @@ data "coder_parameter" "region" {
|
||||
resource "coder_app" "code-server" {
|
||||
count = 1
|
||||
agent_id = coder_agent.main.id
|
||||
display_name = "Code Server"
|
||||
display_name = "code-server"
|
||||
slug = "code-server"
|
||||
url = "http://localhost:8080?folder=/home/coder/"
|
||||
icon = "/icon/code.svg"
|
||||
@@ -284,6 +290,40 @@ resource "coder_agent" "main" {
|
||||
echo "export PATH=$PATH:/home/coder/.fly/bin" >> ~/.bashrc
|
||||
source ~/.bashrc
|
||||
EOT
|
||||
|
||||
metadata {
|
||||
key = "cpu"
|
||||
display_name = "CPU Usage"
|
||||
interval = 5
|
||||
timeout = 5
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4 "%"}'
|
||||
EOT
|
||||
}
|
||||
metadata {
|
||||
key = "memory"
|
||||
display_name = "Memory Usage"
|
||||
interval = 5
|
||||
timeout = 5
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
free -m | awk 'NR==2{printf "%.2f%%\t", $3*100/$2 }'
|
||||
EOT
|
||||
}
|
||||
metadata {
|
||||
key = "disk"
|
||||
display_name = "Disk Usage"
|
||||
interval = 600 # every 10 minutes
|
||||
timeout = 30 # df can take a while on large filesystems
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
df /home/coder | awk '$NF=="/"{printf "%s", $5}'
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
resource "coder_metadata" "workspace" {
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
google = {
|
||||
source = "hashicorp/google"
|
||||
@@ -20,11 +20,13 @@ variable "project_id" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "zone" {
|
||||
name = "What region should your workspace live in?"
|
||||
type = "string"
|
||||
icon = "/emojis/1f30e.png"
|
||||
default = "us-central1-a"
|
||||
mutable = false
|
||||
name = "zone"
|
||||
display_name = "Zone"
|
||||
description = "Which zone should your workspace live in?"
|
||||
type = "string"
|
||||
icon = "/emojis/1f30e.png"
|
||||
default = "us-central1-a"
|
||||
mutable = false
|
||||
option {
|
||||
name = "North America (Northeast)"
|
||||
value = "northamerica-northeast1-a"
|
||||
@@ -86,6 +88,40 @@ resource "coder_agent" "main" {
|
||||
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0
|
||||
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
|
||||
EOT
|
||||
|
||||
metadata {
|
||||
key = "cpu"
|
||||
display_name = "CPU Usage"
|
||||
interval = 5
|
||||
timeout = 5
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4 "%"}'
|
||||
EOT
|
||||
}
|
||||
metadata {
|
||||
key = "memory"
|
||||
display_name = "Memory Usage"
|
||||
interval = 5
|
||||
timeout = 5
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
free -m | awk 'NR==2{printf "%.2f%%\t", $3*100/$2 }'
|
||||
EOT
|
||||
}
|
||||
metadata {
|
||||
key = "disk"
|
||||
display_name = "Disk Usage"
|
||||
interval = 600 # every 10 minutes
|
||||
timeout = 30 # df can take a while on large filesystems
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
df /home/coder | awk '$NF=="/"{printf "%s", $5}'
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
# code-server
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
google = {
|
||||
source = "hashicorp/google"
|
||||
@@ -20,11 +20,13 @@ variable "project_id" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "zone" {
|
||||
name = "What region should your workspace live in?"
|
||||
type = "string"
|
||||
default = "us-central1-a"
|
||||
icon = "/emojis/1f30e.png"
|
||||
mutable = false
|
||||
name = "zone"
|
||||
display_name = "Zone"
|
||||
description = "Which zone should your workspace live in?"
|
||||
type = "string"
|
||||
default = "us-central1-a"
|
||||
icon = "/emojis/1f30e.png"
|
||||
mutable = false
|
||||
option {
|
||||
name = "North America (Northeast)"
|
||||
value = "northamerica-northeast1-a"
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
google = {
|
||||
source = "hashicorp/google"
|
||||
@@ -20,11 +20,13 @@ variable "project_id" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "zone" {
|
||||
name = "What region should your workspace live in?"
|
||||
type = "string"
|
||||
default = "us-central1-a"
|
||||
icon = "/emojis/1f30e.png"
|
||||
mutable = false
|
||||
name = "zone"
|
||||
display_name = "Zone"
|
||||
description = "Which zone should your workspace live in?"
|
||||
type = "string"
|
||||
default = "us-central1-a"
|
||||
icon = "/emojis/1f30e.png"
|
||||
mutable = false
|
||||
option {
|
||||
name = "North America (Northeast)"
|
||||
value = "northamerica-northeast1-a"
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
@@ -18,8 +18,10 @@ provider "kubernetes" {
|
||||
data "coder_workspace" "me" {}
|
||||
|
||||
data "coder_parameter" "os" {
|
||||
name = "Operating system"
|
||||
default = "ubuntu"
|
||||
name = "os"
|
||||
display_name = "Operating system"
|
||||
description = "The operating system to use for your workspace."
|
||||
default = "ubuntu"
|
||||
option {
|
||||
name = "Ubuntu"
|
||||
value = "ubuntu"
|
||||
@@ -33,8 +35,10 @@ data "coder_parameter" "os" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "cpu" {
|
||||
name = "CPU (cores)"
|
||||
default = "2"
|
||||
name = "cpu"
|
||||
display_name = "CPU"
|
||||
description = "The number of CPU cores"
|
||||
default = "2"
|
||||
option {
|
||||
name = "2 Cores"
|
||||
value = "2"
|
||||
@@ -54,8 +58,10 @@ data "coder_parameter" "cpu" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "memory" {
|
||||
name = "Memory (GB)"
|
||||
default = "2"
|
||||
name = "memory"
|
||||
display_name = "Memory"
|
||||
description = "The amount of memory (in GB)"
|
||||
default = "2"
|
||||
option {
|
||||
name = "2 GB"
|
||||
value = "2"
|
||||
@@ -88,12 +94,24 @@ resource "coder_agent" "dev" {
|
||||
# Run once to avoid unnecessary warning: "/" is not a shared mount
|
||||
podman ps
|
||||
EOF
|
||||
|
||||
metadata {
|
||||
key = "disk"
|
||||
display_name = "Disk Usage"
|
||||
interval = 600 # every 10 minutes
|
||||
timeout = 30 # df can take a while on large filesystems
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
df /home/podman | awk '$NF=="/"{printf "%s", $5}'
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
# code-server
|
||||
resource "coder_app" "code-server" {
|
||||
agent_id = coder_agent.dev.id
|
||||
display_name = "Code Server"
|
||||
display_name = "code-server"
|
||||
slug = "code-server"
|
||||
icon = "/icon/code.svg"
|
||||
url = "http://localhost:13337"
|
||||
|
||||
@@ -2,7 +2,7 @@ terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "~> 0.6.17"
|
||||
version = "~> 0.7.0"
|
||||
}
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
@@ -35,10 +35,12 @@ variable "namespace" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "cpu" {
|
||||
name = "CPU (cores)"
|
||||
default = "2"
|
||||
icon = "/icon/memory.svg"
|
||||
mutable = true
|
||||
name = "cpu"
|
||||
display_name = "CPU"
|
||||
description = "The number of CPU cores"
|
||||
default = "2"
|
||||
icon = "/icon/memory.svg"
|
||||
mutable = true
|
||||
option {
|
||||
name = "2 Cores"
|
||||
value = "2"
|
||||
@@ -58,10 +60,12 @@ data "coder_parameter" "cpu" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "memory" {
|
||||
name = "Memory (GB)"
|
||||
default = "2"
|
||||
icon = "/icon/memory.svg"
|
||||
mutable = true
|
||||
name = "memory"
|
||||
display_name = "Memory"
|
||||
description = "The amount of memory in GB"
|
||||
default = "2"
|
||||
icon = "/icon/memory.svg"
|
||||
mutable = true
|
||||
option {
|
||||
name = "2 GB"
|
||||
value = "2"
|
||||
@@ -81,11 +85,13 @@ data "coder_parameter" "memory" {
|
||||
}
|
||||
|
||||
data "coder_parameter" "home_disk_size" {
|
||||
name = "Home Disk Size (GB)"
|
||||
default = "10"
|
||||
type = "number"
|
||||
icon = "/emojis/1f4be.png"
|
||||
mutable = false
|
||||
name = "home_disk_size"
|
||||
display_name = "Home Disk Size"
|
||||
description = "The size of the home disk in GB"
|
||||
default = "10"
|
||||
type = "number"
|
||||
icon = "/emojis/1f4be.png"
|
||||
mutable = false
|
||||
validation {
|
||||
min = 1
|
||||
max = 99999
|
||||
@@ -111,6 +117,18 @@ resource "coder_agent" "main" {
|
||||
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0
|
||||
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
|
||||
EOT
|
||||
|
||||
metadata {
|
||||
key = "disk"
|
||||
display_name = "Disk Usage"
|
||||
interval = 600 # every 10 minutes
|
||||
timeout = 30 # df can take a while on large filesystems
|
||||
script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -e
|
||||
df /home/coder | awk '$NF=="/"{printf "%s", $5}'
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
# code-server
|
||||
|
||||
Reference in New Issue
Block a user