From 725118ec510f51e64461d51f3cca6b1af6dd4542 Mon Sep 17 00:00:00 2001 From: Phorcys <57866459+phorcys420@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:32:03 +0000 Subject: [PATCH 1/6] chore: more sensible variable defaults --- .../templates/digitalocean-linux/README.md | 4 ++-- examples/templates/digitalocean-linux/main.tf | 22 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/templates/digitalocean-linux/README.md b/examples/templates/digitalocean-linux/README.md index e1cbf37393eb2..1ef9599af0c81 100644 --- a/examples/templates/digitalocean-linux/README.md +++ b/examples/templates/digitalocean-linux/README.md @@ -25,13 +25,13 @@ To deploy workspaces as DigitalOcean Droplets, you'll need: - Remove the following sections from the `main.tf` file if you don't want to associate your workspaces with a project: - - `variable "step2_do_project_id"` + - `variable "do_project_id"` - `resource "digitalocean_project_resources" "project"` - **Optional:** DigitalOcean SSH key ID (obtain via the `doctl` CLI by running `doctl compute ssh-key list`) -- Note that this is only required for Fedora images to work. + - Note that this is only required for Fedora images to work. ### Authentication diff --git a/examples/templates/digitalocean-linux/main.tf b/examples/templates/digitalocean-linux/main.tf index ee83e361e5531..f1bc82ed95e81 100644 --- a/examples/templates/digitalocean-linux/main.tf +++ b/examples/templates/digitalocean-linux/main.tf @@ -9,27 +9,26 @@ terraform { } } -provider "coder" { -} +provider "coder" {} -variable "step1_do_project_id" { +variable "do_project_id" { type = string description = <<-EOF - Enter project ID + DigitalOcean project ID $ doctl projects list EOF sensitive = true validation { - # make sure length of alphanumeric string is 36 - condition = length(var.step1_do_project_id) == 36 + # make sure length of alphanumeric string is 36 (UUIDv4 size) + condition = length(var.do_project_id) == 36 error_message = "Invalid Digital Ocean Project ID." } } -variable "step2_do_admin_ssh_key" { +variable "do_admin_ssh_key" { type = number description = <<-EOF Enter admin SSH key ID (some Droplet images require an SSH key to be set): @@ -40,10 +39,11 @@ variable "step2_do_admin_ssh_key" { $ doctl compute ssh-key list EOF - sensitive = true + sensitive = true + default = 0 validation { - condition = var.step2_do_admin_ssh_key >= 0 + condition = var.do_admin_ssh_key >= 0 error_message = "Invalid Digital Ocean SSH key ID, a number is required." } } @@ -291,11 +291,11 @@ resource "digitalocean_droplet" "workspace" { coder_agent_token = coder_agent.main.token }) # Required to provision Fedora. - ssh_keys = var.step2_do_admin_ssh_key > 0 ? [var.step2_do_admin_ssh_key] : [] + ssh_keys = var.do_admin_ssh_key > 0 ? [var.do_admin_ssh_key] : [] } resource "digitalocean_project_resources" "project" { - project = var.step1_do_project_id + project = var.do_project_id # Workaround for terraform plan when using count. resources = length(digitalocean_droplet.workspace) > 0 ? [ digitalocean_volume.home_volume.urn, From 51d147d15d145ea19f38f03f884cffb070d9597d Mon Sep 17 00:00:00 2001 From: Phorcys <57866459+phorcys420@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:05:29 +0000 Subject: [PATCH 2/6] chore: clean readme --- .../templates/digitalocean-linux/README.md | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/examples/templates/digitalocean-linux/README.md b/examples/templates/digitalocean-linux/README.md index 1ef9599af0c81..7475c1b7c8654 100644 --- a/examples/templates/digitalocean-linux/README.md +++ b/examples/templates/digitalocean-linux/README.md @@ -17,16 +17,15 @@ Provision DigitalOcean Droplets as [Coder workspaces](https://coder.com/docs/wor To deploy workspaces as DigitalOcean Droplets, you'll need: -- DigitalOcean [personal access token (PAT)](https://docs.digitalocean.com/reference/api/create-personal-access-token/) +- DigitalOcean [personal access token (PAT)](https://docs.digitalocean.com/reference/api/create-personal-access-token) -- DigitalOcean project ID (you can get your project information via the `doctl` - CLI by running `doctl projects list`) +- DigitalOcean project ID (you can get your project information via the `doctl` CLI by running `doctl projects list`) -- Remove the following sections from the `main.tf` file if you don't want to - associate your workspaces with a project: + - Remove the following sections from the `main.tf` file if you don't want to + associate your workspaces with a project: - - `variable "do_project_id"` - - `resource "digitalocean_project_resources" "project"` + - `variable "do_project_id"` + - `resource "digitalocean_project_resources" "project"` - **Optional:** DigitalOcean SSH key ID (obtain via the `doctl` CLI by running `doctl compute ssh-key list`) @@ -35,20 +34,19 @@ To deploy workspaces as DigitalOcean Droplets, you'll need: ### Authentication -This template assumes that coderd is run in an environment that is authenticated -with Digital Ocean. Obtain a [Digital Ocean Personal Access -Token](https://cloud.digitalocean.com/account/api/tokens) and set the -environment variable `DIGITALOCEAN_TOKEN` to the access token before starting -coderd. For other ways to authenticate [consult the Terraform docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs). +This template assumes that `coderd` is run in an environment that is authenticated with Digital Ocean. + +Obtain a [Digital Ocean Personal Access Token](https://cloud.digitalocean.com/account/api/tokens) and set the `DIGITALOCEAN_TOKEN` environment variable to the access token before starting `coderd`. +For other ways to authenticate [consult the Terraform provider's docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs). ## Architecture This template provisions the following resources: -- Azure VM (ephemeral, deleted on stop) +- DigitalOcean VM (ephemeral, deleted on stop) - Managed disk (persistent, mounted to `/home/coder`) This means, when the workspace restarts, any tools or files outside of the home directory are not persisted. To pre-bake tools into the workspace (e.g. `python3`), modify the VM image, or use a [startup script](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/script). -> **Note** +> [!NOTE] > This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case. From 47a38082818e999f0282f231844529d54654b4ff Mon Sep 17 00:00:00 2001 From: Phorcys <57866459+phorcys420@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:07:53 +0000 Subject: [PATCH 3/6] chore: format and lint --- examples/templates/digitalocean-linux/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/templates/digitalocean-linux/main.tf b/examples/templates/digitalocean-linux/main.tf index f1bc82ed95e81..fb11f0513ec1c 100644 --- a/examples/templates/digitalocean-linux/main.tf +++ b/examples/templates/digitalocean-linux/main.tf @@ -39,8 +39,8 @@ variable "do_admin_ssh_key" { $ doctl compute ssh-key list EOF - sensitive = true - default = 0 + sensitive = true + default = 0 validation { condition = var.do_admin_ssh_key >= 0 From 3b2fd4d79b92e18b20dcc16057bde84dd858b4fb Mon Sep 17 00:00:00 2001 From: Phorcys <57866459+phorcys420@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:24:36 +0000 Subject: [PATCH 4/6] chore: make gen --- examples/examples.gen.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/examples.gen.json b/examples/examples.gen.json index 0f7d7f605c8fe..bcf551cab2817 100644 --- a/examples/examples.gen.json +++ b/examples/examples.gen.json @@ -66,7 +66,7 @@ "linux", "digitalocean" ], - "markdown": "\n# Remote Development on DigitalOcean Droplets\n\nProvision DigitalOcean Droplets as [Coder workspaces](https://coder.com/docs/workspaces) with this example template.\n\n\u003c!-- TODO: Add screenshot --\u003e\n\n## Prerequisites\n\nTo deploy workspaces as DigitalOcean Droplets, you'll need:\n\n- DigitalOcean [personal access token (PAT)](https://docs.digitalocean.com/reference/api/create-personal-access-token/)\n\n- DigitalOcean project ID (you can get your project information via the `doctl`\n CLI by running `doctl projects list`)\n\n- Remove the following sections from the `main.tf` file if you don't want to\n associate your workspaces with a project:\n\n - `variable \"step2_do_project_id\"`\n - `resource \"digitalocean_project_resources\" \"project\"`\n\n- **Optional:** DigitalOcean SSH key ID (obtain via the `doctl` CLI by running\n `doctl compute ssh-key list`)\n\n- Note that this is only required for Fedora images to work.\n\n### Authentication\n\nThis template assumes that coderd is run in an environment that is authenticated\nwith Digital Ocean. Obtain a [Digital Ocean Personal Access\nToken](https://cloud.digitalocean.com/account/api/tokens) and set the\nenvironment variable `DIGITALOCEAN_TOKEN` to the access token before starting\ncoderd. For other ways to authenticate [consult the Terraform docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs).\n\n## Architecture\n\nThis template provisions the following resources:\n\n- Azure VM (ephemeral, deleted on stop)\n- Managed disk (persistent, mounted to `/home/coder`)\n\nThis means, when the workspace restarts, any tools or files outside of the home directory are not persisted. To pre-bake tools into the workspace (e.g. `python3`), modify the VM image, or use a [startup script](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/script).\n\n\u003e **Note**\n\u003e This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.\n" + "markdown": "\n# Remote Development on DigitalOcean Droplets\n\nProvision DigitalOcean Droplets as [Coder workspaces](https://coder.com/docs/workspaces) with this example template.\n\n\u003c!-- TODO: Add screenshot --\u003e\n\n## Prerequisites\n\nTo deploy workspaces as DigitalOcean Droplets, you'll need:\n\n- DigitalOcean [personal access token (PAT)](https://docs.digitalocean.com/reference/api/create-personal-access-token)\n\n- DigitalOcean project ID (you can get your project information via the `doctl` CLI by running `doctl projects list`)\n\n\t- Remove the following sections from the `main.tf` file if you don't want to\n\t\tassociate your workspaces with a project:\n\n\t\t- `variable \"do_project_id\"`\n\t\t- `resource \"digitalocean_project_resources\" \"project\"`\n\n- **Optional:** DigitalOcean SSH key ID (obtain via the `doctl` CLI by running\n `doctl compute ssh-key list`)\n\n\t- Note that this is only required for Fedora images to work.\n\n### Authentication\n\nThis template assumes that `coderd` is run in an environment that is authenticated with Digital Ocean.\n\nObtain a [Digital Ocean Personal Access Token](https://cloud.digitalocean.com/account/api/tokens) and set the `DIGITALOCEAN_TOKEN` environment variable to the access token before starting `coderd`.\nFor other ways to authenticate [consult the Terraform provider's docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs).\n\n## Architecture\n\nThis template provisions the following resources:\n\n- DigitalOcean VM (ephemeral, deleted on stop)\n- Managed disk (persistent, mounted to `/home/coder`)\n\nThis means, when the workspace restarts, any tools or files outside of the home directory are not persisted. To pre-bake tools into the workspace (e.g. `python3`), modify the VM image, or use a [startup script](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/script).\n\n\u003e [!NOTE]\n\u003e This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.\n" }, { "id": "docker", From 29a4aa504c31c9b10b697d297e13788ccdf2630f Mon Sep 17 00:00:00 2001 From: Phorcys <57866459+phorcys420@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:36:40 +0000 Subject: [PATCH 5/6] chore: format --- examples/templates/digitalocean-linux/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/templates/digitalocean-linux/README.md b/examples/templates/digitalocean-linux/README.md index 7475c1b7c8654..73fab87fa89c1 100644 --- a/examples/templates/digitalocean-linux/README.md +++ b/examples/templates/digitalocean-linux/README.md @@ -21,16 +21,16 @@ To deploy workspaces as DigitalOcean Droplets, you'll need: - DigitalOcean project ID (you can get your project information via the `doctl` CLI by running `doctl projects list`) - - Remove the following sections from the `main.tf` file if you don't want to - associate your workspaces with a project: + - Remove the following sections from the `main.tf` file if you don't want to + associate your workspaces with a project: - - `variable "do_project_id"` - - `resource "digitalocean_project_resources" "project"` + - `variable "do_project_id"` + - `resource "digitalocean_project_resources" "project"` - **Optional:** DigitalOcean SSH key ID (obtain via the `doctl` CLI by running `doctl compute ssh-key list`) - - Note that this is only required for Fedora images to work. + - Note that this is only required for Fedora images to work. ### Authentication From 59f6a6285ea331539f7642f14476164a33756c9c Mon Sep 17 00:00:00 2001 From: Phorcys <57866459+phorcys420@users.noreply.github.com> Date: Tue, 24 Dec 2024 18:10:14 +0000 Subject: [PATCH 6/6] chore: update variable IDs --- examples/examples.gen.json | 2 +- examples/templates/digitalocean-linux/README.md | 6 +++--- examples/templates/digitalocean-linux/main.tf | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/examples.gen.json b/examples/examples.gen.json index bcf551cab2817..b04cbb99906fc 100644 --- a/examples/examples.gen.json +++ b/examples/examples.gen.json @@ -66,7 +66,7 @@ "linux", "digitalocean" ], - "markdown": "\n# Remote Development on DigitalOcean Droplets\n\nProvision DigitalOcean Droplets as [Coder workspaces](https://coder.com/docs/workspaces) with this example template.\n\n\u003c!-- TODO: Add screenshot --\u003e\n\n## Prerequisites\n\nTo deploy workspaces as DigitalOcean Droplets, you'll need:\n\n- DigitalOcean [personal access token (PAT)](https://docs.digitalocean.com/reference/api/create-personal-access-token)\n\n- DigitalOcean project ID (you can get your project information via the `doctl` CLI by running `doctl projects list`)\n\n\t- Remove the following sections from the `main.tf` file if you don't want to\n\t\tassociate your workspaces with a project:\n\n\t\t- `variable \"do_project_id\"`\n\t\t- `resource \"digitalocean_project_resources\" \"project\"`\n\n- **Optional:** DigitalOcean SSH key ID (obtain via the `doctl` CLI by running\n `doctl compute ssh-key list`)\n\n\t- Note that this is only required for Fedora images to work.\n\n### Authentication\n\nThis template assumes that `coderd` is run in an environment that is authenticated with Digital Ocean.\n\nObtain a [Digital Ocean Personal Access Token](https://cloud.digitalocean.com/account/api/tokens) and set the `DIGITALOCEAN_TOKEN` environment variable to the access token before starting `coderd`.\nFor other ways to authenticate [consult the Terraform provider's docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs).\n\n## Architecture\n\nThis template provisions the following resources:\n\n- DigitalOcean VM (ephemeral, deleted on stop)\n- Managed disk (persistent, mounted to `/home/coder`)\n\nThis means, when the workspace restarts, any tools or files outside of the home directory are not persisted. To pre-bake tools into the workspace (e.g. `python3`), modify the VM image, or use a [startup script](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/script).\n\n\u003e [!NOTE]\n\u003e This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.\n" + "markdown": "\n# Remote Development on DigitalOcean Droplets\n\nProvision DigitalOcean Droplets as [Coder workspaces](https://coder.com/docs/workspaces) with this example template.\n\n\u003c!-- TODO: Add screenshot --\u003e\n\n## Prerequisites\n\nTo deploy workspaces as DigitalOcean Droplets, you'll need:\n\n- DigitalOcean [personal access token (PAT)](https://docs.digitalocean.com/reference/api/create-personal-access-token)\n\n- DigitalOcean project ID (you can get your project information via the `doctl` CLI by running `doctl projects list`)\n\n - Remove the following sections from the `main.tf` file if you don't want to\n associate your workspaces with a project:\n\n - `variable \"project_uuid\"`\n - `resource \"digitalocean_project_resources\" \"project\"`\n\n- **Optional:** DigitalOcean SSH key ID (obtain via the `doctl` CLI by running\n `doctl compute ssh-key list`)\n\n - Note that this is only required for Fedora images to work.\n\n### Authentication\n\nThis template assumes that the Coder Provisioner is run in an environment that is authenticated with Digital Ocean.\n\nObtain a [Digital Ocean Personal Access Token](https://cloud.digitalocean.com/account/api/tokens) and set the `DIGITALOCEAN_TOKEN` environment variable to the access token.\nFor other ways to authenticate [consult the Terraform provider's docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs).\n\n## Architecture\n\nThis template provisions the following resources:\n\n- DigitalOcean VM (ephemeral, deleted on stop)\n- Managed disk (persistent, mounted to `/home/coder`)\n\nThis means, when the workspace restarts, any tools or files outside of the home directory are not persisted. To pre-bake tools into the workspace (e.g. `python3`), modify the VM image, or use a [startup script](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/script).\n\n\u003e [!NOTE]\n\u003e This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.\n" }, { "id": "docker", diff --git a/examples/templates/digitalocean-linux/README.md b/examples/templates/digitalocean-linux/README.md index 73fab87fa89c1..1776c7a1afbf4 100644 --- a/examples/templates/digitalocean-linux/README.md +++ b/examples/templates/digitalocean-linux/README.md @@ -24,7 +24,7 @@ To deploy workspaces as DigitalOcean Droplets, you'll need: - Remove the following sections from the `main.tf` file if you don't want to associate your workspaces with a project: - - `variable "do_project_id"` + - `variable "project_uuid"` - `resource "digitalocean_project_resources" "project"` - **Optional:** DigitalOcean SSH key ID (obtain via the `doctl` CLI by running @@ -34,9 +34,9 @@ To deploy workspaces as DigitalOcean Droplets, you'll need: ### Authentication -This template assumes that `coderd` is run in an environment that is authenticated with Digital Ocean. +This template assumes that the Coder Provisioner is run in an environment that is authenticated with Digital Ocean. -Obtain a [Digital Ocean Personal Access Token](https://cloud.digitalocean.com/account/api/tokens) and set the `DIGITALOCEAN_TOKEN` environment variable to the access token before starting `coderd`. +Obtain a [Digital Ocean Personal Access Token](https://cloud.digitalocean.com/account/api/tokens) and set the `DIGITALOCEAN_TOKEN` environment variable to the access token. For other ways to authenticate [consult the Terraform provider's docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs). ## Architecture diff --git a/examples/templates/digitalocean-linux/main.tf b/examples/templates/digitalocean-linux/main.tf index fb11f0513ec1c..89665c120f5e9 100644 --- a/examples/templates/digitalocean-linux/main.tf +++ b/examples/templates/digitalocean-linux/main.tf @@ -11,7 +11,7 @@ terraform { provider "coder" {} -variable "do_project_id" { +variable "project_uuid" { type = string description = <<-EOF DigitalOcean project ID @@ -22,16 +22,16 @@ variable "do_project_id" { validation { # make sure length of alphanumeric string is 36 (UUIDv4 size) - condition = length(var.do_project_id) == 36 + condition = length(var.project_uuid) == 36 error_message = "Invalid Digital Ocean Project ID." } } -variable "do_admin_ssh_key" { +variable "ssh_key_id" { type = number description = <<-EOF - Enter admin SSH key ID (some Droplet images require an SSH key to be set): + DigitalOcean SSH key ID (some Droplet images require an SSH key to be set): Can be set to "0" for no key. @@ -43,7 +43,7 @@ variable "do_admin_ssh_key" { default = 0 validation { - condition = var.do_admin_ssh_key >= 0 + condition = var.ssh_key_id >= 0 error_message = "Invalid Digital Ocean SSH key ID, a number is required." } } @@ -291,11 +291,11 @@ resource "digitalocean_droplet" "workspace" { coder_agent_token = coder_agent.main.token }) # Required to provision Fedora. - ssh_keys = var.do_admin_ssh_key > 0 ? [var.do_admin_ssh_key] : [] + ssh_keys = var.ssh_key_id > 0 ? [var.ssh_key_id] : [] } resource "digitalocean_project_resources" "project" { - project = var.do_project_id + project = var.project_uuid # Workaround for terraform plan when using count. resources = length(digitalocean_droplet.workspace) > 0 ? [ digitalocean_volume.home_volume.urn,