Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 73 additions & 88 deletions examples/templates/do-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,40 @@ 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 = "CentOS Stream 9"
value = "centos-stream-9-x64"
icon = "/icon/centos.svg"
}
option {
name = "CentOS Stream 8"
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"
Expand All @@ -86,24 +101,24 @@ data "coder_parameter" "droplet_image" {
icon = "/icon/debian.svg"
}
option {
name = "CentOS Stream 9"
value = "centos-stream-9-x64"
icon = "/icon/centos.svg"
}
option {
name = "CentOS Stream 8"
value = "centos-stream-8-x64"
icon = "/icon/centos.svg"
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"
}
}

Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
}
}

Expand All @@ -163,70 +175,56 @@ 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"
name = "Canada (Toronto)"
value = "tor1"
icon = "/emojis/1f1e8-1f1e6.png"
}
option {
name = "San Francisco 3"
value = "sfo3"
icon = "/emojis/1f1fa-1f1f8.png"
name = "Germany (Frankfurt)"
value = "fra1"
icon = "/emojis/1f1e9-1f1ea.png"
}
option {
name = "Amsterdam 2"
value = "ams2"
icon = "/emojis/1f1f3-1f1f1.png"
name = "India (Bangalore)"
value = "blr1"
icon = "/emojis/1f1ee-1f1f3.png"
}
option {
name = "Amsterdam 3"
name = "Netherlands (Amsterdam)"
value = "ams3"
icon = "/emojis/1f1f3-1f1f1.png"
}
option {
name = "Singapore 1"
name = "Singapore"
value = "sgp1"
icon = "/emojis/1f1f8-1f1ec.png"
}
option {
name = "London 1"
name = "United Kingdom (London)"
value = "lon1"
icon = "/emojis/1f1ec-1f1e7.png"
}
option {
name = "Frankfurt 1"
value = "fra1"
icon = "/emojis/1f1e9-1f1ea.png"
name = "United States (California - 2)"
value = "sfo2"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "Toronto 1"
value = "tor1"
icon = "/emojis/1f1e8-1f1e6.png"
name = "United States (California - 3)"
value = "sfo3"
icon = "/emojis/1f1fa-1f1f8.png"
}
option {
name = "Bangalore 1"
value = "blr1"
icon = "/emojis/1f1ee-1f1f3.png"
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"
}
}

Expand All @@ -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" {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions site/src/theme/icons.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
"almalinux.svg",
"android-studio.svg",
"apache-guacamole.svg",
"apple-black.svg",
Expand Down
16 changes: 16 additions & 0 deletions site/static/icon/almalinux.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.