chore: update Digital Ocean example template (#11528) (#11535)

Co-authored-by: Muhammad Atif Ali <atif@coder.com>
This commit is contained in:
bamhm182
2024-01-11 00:00:25 +00:00
committed by GitHub
co-authored by Muhammad Atif Ali
parent 9b437032e9
commit 4e5367c4a4
3 changed files with 108 additions and 106 deletions
+91 -106
View File
@@ -56,35 +56,25 @@ data "coder_parameter" "droplet_image" {
type = "string"
mutable = false
option {
name = "Ubuntu 22.04"
value = "ubuntu-22-04-x64"
icon = "/icon/ubuntu.svg"
name = "AlmaLinux 9"
value = "almalinux-9-x64"
icon = "/icon/almalinux.svg"
}
option {
name = "Ubuntu 20.04"
value = "ubuntu-20-04-x64"
icon = "/icon/ubuntu.svg"
name = "AlmaLinux 8"
value = "almalinux-8-x64"
icon = "/icon/almalinux.svg"
}
option {
name = "Fedora 36"
value = "fedora-36-x64"
name = "Fedora 39"
value = "fedora-39-x64"
icon = "/icon/fedora.svg"
}
option {
name = "Fedora 35"
value = "fedora-35-x64"
name = "Fedora 38"
value = "fedora-38-x64"
icon = "/icon/fedora.svg"
}
option {
name = "Debian 11"
value = "debian-11-x64"
icon = "/icon/debian.svg"
}
option {
name = "Debian 10"
value = "debian-10-x64"
icon = "/icon/debian.svg"
}
option {
name = "CentOS Stream 9"
value = "centos-stream-9-x64"
@@ -95,15 +85,40 @@ data "coder_parameter" "droplet_image" {
value = "centos-stream-8-x64"
icon = "/icon/centos.svg"
}
option {
name = "Debian 12"
value = "debian-12-x64"
icon = "/icon/debian.svg"
}
option {
name = "Debian 11"
value = "debian-11-x64"
icon = "/icon/debian.svg"
}
option {
name = "Debian 10"
value = "debian-10-x64"
icon = "/icon/debian.svg"
}
option {
name = "Rocky Linux 9"
value = "rockylinux-9-x64"
icon = "/icon/rockylinux.svg"
}
option {
name = "Rocky Linux 8"
value = "rockylinux-8-x64"
icon = "/icon/rockylinux.svg"
}
option {
name = "Rocky Linux 8.4"
value = "rockylinux-8-4-x64"
icon = "/icon/rockylinux.svg"
name = "Ubuntu 22.04 (LTS)"
value = "ubuntu-22-04-x64"
icon = "/icon/ubuntu.svg"
}
option {
name = "Ubuntu 20.04 (LTS)"
value = "ubuntu-20-04-x64"
icon = "/icon/ubuntu.svg"
}
}
@@ -115,6 +130,8 @@ data "coder_parameter" "droplet_size" {
type = "string"
icon = "/icon/memory.svg"
mutable = false
# s-1vcpu-512mb-10gb is unsupported in tor1, blr1, lon1, sfo2, and nyc3 regions
# s-8vcpu-16gb access requires a support ticket with Digital Ocean
option {
name = "1 vCPU, 1 GB RAM"
value = "s-1vcpu-1gb"
@@ -135,13 +152,8 @@ data "coder_parameter" "droplet_size" {
name = "4 vCPU, 8 GB RAM"
value = "s-4vcpu-8gb"
}
option {
name = "8 vCPU, 16 GB RAM"
value = "s-8vcpu-16gb"
}
}
data "coder_parameter" "home_volume_size" {
name = "home_volume_size"
display_name = "Home volume size"
@@ -151,7 +163,7 @@ data "coder_parameter" "home_volume_size" {
mutable = false
validation {
min = 1
max = 999999
max = 100 # Sizes larger than 100 GB require a support ticket with Digital Ocean
}
}
@@ -163,71 +175,57 @@ data "coder_parameter" "region" {
type = "string"
default = "ams3"
mutable = false
# nyc1, sfo1, and ams2 regions were excluded because they do not support volumes, which are used to persist data while decreasing cost
option {
name = "New York 1"
value = "nyc1"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "New York 2"
value = "nyc2"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "New York 3"
value = "nyc3"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "San Francisco 1"
value = "sfo1"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "San Francisco 2"
value = "sfo2"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "San Francisco 3"
value = "sfo3"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "Amsterdam 2"
value = "ams2"
icon = "/emojis/1f1f3-1f1f1.png"
}
option {
name = "Amsterdam 3"
value = "ams3"
icon = "/emojis/1f1f3-1f1f1.png"
}
option {
name = "Singapore 1"
value = "sgp1"
icon = "/emojis/1f1f8-1f1ec.png"
}
option {
name = "London 1"
value = "lon1"
icon = "/emojis/1f1ec-1f1e7.png"
}
option {
name = "Frankfurt 1"
value = "fra1"
icon = "/emojis/1f1e9-1f1ea.png"
}
option {
name = "Toronto 1"
name = "Canada (Toronto)"
value = "tor1"
icon = "/emojis/1f1e8-1f1e6.png"
}
option {
name = "Bangalore 1"
name = "Germany (Frankfurt)"
value = "fra1"
icon = "/emojis/1f1e9-1f1ea.png"
}
option {
name = "India (Bangalore)"
value = "blr1"
icon = "/emojis/1f1ee-1f1f3.png"
}
option {
name = "Netherlands (Amsterdam)"
value = "ams3"
icon = "/emojis/1f1f3-1f1f1.png"
}
option {
name = "Singapore"
value = "sgp1"
icon = "/emojis/1f1f8-1f1ec.png"
}
option {
name = "United Kingdom (London)"
value = "lon1"
icon = "/emojis/1f1ec-1f1e7.png"
}
option {
name = "United States (California - 2)"
value = "sfo2"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "United States (California - 3)"
value = "sfo3"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "United States (New York - 1)"
value = "nyc1"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "United States (New York - 3)"
value = "nyc3"
icon = "/emojis/1f1fa-1f1f8.png"
}
}
# Configure the DigitalOcean Provider
@@ -247,35 +245,22 @@ resource "coder_agent" "main" {
display_name = "CPU Usage"
interval = 5
timeout = 5
script = <<-EOT
#!/bin/bash
set -e
top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4 "%"}'
EOT
script = "coder stat cpu"
}
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
script = "coder stat mem"
}
metadata {
key = "disk"
display_name = "Disk Usage"
key = "home"
display_name = "Home 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
script = "coder stat disk --path /home/${lower(data.coder_workspace.me.owner)}"
}
}
resource "digitalocean_volume" "home_volume" {
@@ -293,13 +278,13 @@ resource "digitalocean_volume" "home_volume" {
resource "digitalocean_droplet" "workspace" {
region = data.coder_parameter.region.value
count = data.coder_workspace.me.start_count
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}"
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}"
image = data.coder_parameter.droplet_image.value
size = data.coder_parameter.droplet_size.value
volume_ids = [digitalocean_volume.home_volume.id]
user_data = templatefile("cloud-config.yaml.tftpl", {
username = data.coder_workspace.me.owner
username = lower(data.coder_workspace.me.owner)
home_volume_label = digitalocean_volume.home_volume.initial_filesystem_label
init_script = base64encode(coder_agent.main.init_script)
coder_agent_token = coder_agent.main.token