Skip to content

chore: add agent metadata to example templates #7044

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 10 commits into from
Apr 12, 2023
24 changes: 13 additions & 11 deletions examples/templates/aws-ecs-container/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "~> 0.6.17"
version = "~> 0.7.0"
}
aws = {
source = "hashicorp/aws"
Expand All @@ -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
Expand Down
54 changes: 45 additions & 9 deletions examples/templates/aws-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "~> 0.6.17"
version = "~> 0.7.0"
}
aws = {
source = "hashicorp/aws"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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" {
Expand Down
20 changes: 11 additions & 9 deletions examples/templates/aws-windows/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "~> 0.6.17"
version = "~> 0.7.0"
}
aws = {
source = "hashicorp/aws"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
71 changes: 54 additions & 17 deletions examples/templates/azure-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "~> 0.6.17"
version = "~> 0.7.0"
}
azurerm = {
source = "hashicorp/azurerm"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
83 changes: 62 additions & 21 deletions examples/templates/do-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "~> 0.6.17"
version = "~> 0.7.0"
}
digitalocean = {
source = "digitalocean/digitalocean"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -142,24 +146,26 @@ 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
}
}

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"
Expand Down Expand Up @@ -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" {
Expand Down
Loading