chore: update templates to use rich parameters (#6397)

This commit is contained in:
Muhammad Atif Ali
2023-03-15 13:11:52 +00:00
committed by GitHub
parent 3cf235c564
commit a0e096bcfe
21 changed files with 1251 additions and 358 deletions
+177 -35
View File
@@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "~> 0.6.12"
version = "~> 0.6.17"
}
digitalocean = {
source = "digitalocean/digitalocean"
@@ -11,6 +11,10 @@ terraform {
}
}
provider "coder" {
feature_use_managed_variables = true
}
variable "step1_do_project_id" {
type = string
description = <<-EOF
@@ -21,9 +25,11 @@ variable "step1_do_project_id" {
sensitive = true
validation {
# make sure length of alphanumeric string is 36
condition = length(var.step1_do_project_id) == 36
error_message = "Invalid Digital Ocean Project ID."
}
}
variable "step2_do_admin_ssh_key" {
@@ -45,43 +51,179 @@ variable "step2_do_admin_ssh_key" {
}
}
variable "droplet_image" {
type = string
description = "Which Droplet image would you like to use for your workspace?"
default = "ubuntu-22-04-x64"
validation {
condition = contains(["ubuntu-22-04-x64", "ubuntu-20-04-x64", "fedora-36-x64", "fedora-35-x64", "debian-11-x64", "debian-10-x64", "centos-stream-9-x64", "centos-stream-8-x64", "rockylinux-8-x64", "rockylinux-8-4-x64"], var.droplet_image)
error_message = "Value must be ubuntu-22-04-x64, ubuntu-20-04-x64, fedora-36-x64, fedora-35-x64, debian-11-x64, debian-10-x64, centos-stream-9-x64, centos-stream-8-x64, rockylinux-8-x64 or rockylinux-8-4-x64."
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
option {
name = "Ubuntu 22.04"
value = "ubuntu-22-04-x64"
icon = "/icon/ubuntu.svg"
}
option {
name = "Ubuntu 20.04"
value = "ubuntu-20-04-x64"
icon = "/icon/ubuntu.svg"
}
option {
name = "Fedora 36"
value = "fedora-36-x64"
icon = "/icon/fedora.svg"
}
option {
name = "Fedora 35"
value = "fedora-35-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"
icon = "/icon/centos.svg"
}
option {
name = "CentOS Stream 8"
value = "centos-stream-8-x64"
icon = "/icon/centos.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"
}
}
variable "droplet_size" {
type = string
description = "Which Droplet configuration would you like to use?"
default = "s-1vcpu-1gb"
validation {
condition = contains(["s-1vcpu-1gb", "s-1vcpu-2gb", "s-2vcpu-2gb", "s-2vcpu-4gb", "s-4vcpu-8gb", "s-8vcpu-16gb"], var.droplet_size)
error_message = "Value must be s-1vcpu-1gb, s-1vcpu-2gb, s-2vcpu-2gb, s-2vcpu-4gb, s-4vcpu-8gb or s-8vcpu-16gb."
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
option {
name = "1 vCPU, 1 GB RAM"
value = "s-1vcpu-1gb"
}
option {
name = "1 vCPU, 2 GB RAM"
value = "s-1vcpu-2gb"
}
option {
name = "2 vCPU, 2 GB RAM"
value = "s-2vcpu-2gb"
}
option {
name = "2 vCPU, 4 GB RAM"
value = "s-2vcpu-4gb"
}
option {
name = "4 vCPU, 8 GB RAM"
value = "s-4vcpu-8gb"
}
option {
name = "8 vCPU, 16 GB RAM"
value = "s-8vcpu-16gb"
}
}
variable "home_volume_size" {
type = number
description = "How large would you like your home volume to be (in GB)?"
default = 20
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
validation {
condition = var.home_volume_size >= 1
error_message = "Value must be greater than or equal to 1."
min = 1
max = 999999
}
}
variable "region" {
type = string
description = "Which region would you like to use?"
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"
validation {
condition = contains(["nyc1", "nyc2", "nyc3", "sfo1", "sfo2", "sfo3", "ams2", "ams3", "sgp1", "lon1", "fra1", "tor1", "blr1"], var.region)
error_message = "Value must be nyc1, nyc2, nyc3, sfo1, sfo2, sfo3, ams2, ams3, sgp1, lon1, fra1, tor1 or blr1."
mutable = false
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"
value = "tor1"
icon = "/emojis/1f1e8-1f1e6.png"
}
option {
name = "Bangalore 1"
value = "blr1"
icon = "/emojis/1f1ee-1f1f3.png"
}
}
@@ -101,9 +243,9 @@ resource "coder_agent" "main" {
}
resource "digitalocean_volume" "home_volume" {
region = var.region
region = data.coder_parameter.region.value
name = "coder-${data.coder_workspace.me.id}-home"
size = var.home_volume_size
size = data.coder_parameter.home_volume_size.value
initial_filesystem_type = "ext4"
initial_filesystem_label = "coder-home"
# Protect the volume from being deleted due to changes in attributes.
@@ -113,11 +255,12 @@ resource "digitalocean_volume" "home_volume" {
}
resource "digitalocean_droplet" "workspace" {
region = var.region
count = data.coder_workspace.me.start_count
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}"
image = var.droplet_image
size = var.droplet_size
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}"
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
@@ -161,5 +304,4 @@ resource "coder_metadata" "volume-info" {
key = "size"
value = "${digitalocean_volume.home_volume.size} GiB"
}
}