Skip to content

Commit 03edd60

Browse files
authored
chore(examples/templates/digitalocean-linux): make template more friendly (#15938)
1 parent 26b1f1c commit 03edd60

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

examples/examples.gen.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"linux",
6767
"digitalocean"
6868
],
69-
"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"
69+
"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"
7070
},
7171
{
7272
"id": "docker",

examples/templates/digitalocean-linux/README.md

+13-15
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,36 @@ Provision DigitalOcean Droplets as [Coder workspaces](https://coder.com/docs/wor
1717

1818
To deploy workspaces as DigitalOcean Droplets, you'll need:
1919

20-
- DigitalOcean [personal access token (PAT)](https://docs.digitalocean.com/reference/api/create-personal-access-token/)
20+
- DigitalOcean [personal access token (PAT)](https://docs.digitalocean.com/reference/api/create-personal-access-token)
2121

22-
- DigitalOcean project ID (you can get your project information via the `doctl`
23-
CLI by running `doctl projects list`)
22+
- DigitalOcean project ID (you can get your project information via the `doctl` CLI by running `doctl projects list`)
2423

25-
- Remove the following sections from the `main.tf` file if you don't want to
26-
associate your workspaces with a project:
24+
- Remove the following sections from the `main.tf` file if you don't want to
25+
associate your workspaces with a project:
2726

28-
- `variable "step2_do_project_id"`
29-
- `resource "digitalocean_project_resources" "project"`
27+
- `variable "project_uuid"`
28+
- `resource "digitalocean_project_resources" "project"`
3029

3130
- **Optional:** DigitalOcean SSH key ID (obtain via the `doctl` CLI by running
3231
`doctl compute ssh-key list`)
3332

34-
- Note that this is only required for Fedora images to work.
33+
- Note that this is only required for Fedora images to work.
3534

3635
### Authentication
3736

38-
This template assumes that coderd is run in an environment that is authenticated
39-
with Digital Ocean. Obtain a [Digital Ocean Personal Access
40-
Token](https://cloud.digitalocean.com/account/api/tokens) and set the
41-
environment variable `DIGITALOCEAN_TOKEN` to the access token before starting
42-
coderd. For other ways to authenticate [consult the Terraform docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs).
37+
This template assumes that the Coder Provisioner is run in an environment that is authenticated with Digital Ocean.
38+
39+
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.
40+
For other ways to authenticate [consult the Terraform provider's docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs).
4341

4442
## Architecture
4543

4644
This template provisions the following resources:
4745

48-
- Azure VM (ephemeral, deleted on stop)
46+
- DigitalOcean VM (ephemeral, deleted on stop)
4947
- Managed disk (persistent, mounted to `/home/coder`)
5048

5149
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).
5250

53-
> **Note**
51+
> [!NOTE]
5452
> This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.

examples/templates/digitalocean-linux/main.tf

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,29 @@ terraform {
99
}
1010
}
1111

12-
provider "coder" {
13-
}
12+
provider "coder" {}
1413

15-
variable "step1_do_project_id" {
14+
variable "project_uuid" {
1615
type = string
1716
description = <<-EOF
18-
Enter project ID
17+
DigitalOcean project ID
1918
2019
$ doctl projects list
2120
EOF
2221
sensitive = true
2322

2423
validation {
25-
# make sure length of alphanumeric string is 36
26-
condition = length(var.step1_do_project_id) == 36
24+
# make sure length of alphanumeric string is 36 (UUIDv4 size)
25+
condition = length(var.project_uuid) == 36
2726
error_message = "Invalid Digital Ocean Project ID."
2827
}
2928

3029
}
3130

32-
variable "step2_do_admin_ssh_key" {
31+
variable "ssh_key_id" {
3332
type = number
3433
description = <<-EOF
35-
Enter admin SSH key ID (some Droplet images require an SSH key to be set):
34+
DigitalOcean SSH key ID (some Droplet images require an SSH key to be set):
3635
3736
Can be set to "0" for no key.
3837
@@ -41,9 +40,10 @@ variable "step2_do_admin_ssh_key" {
4140
$ doctl compute ssh-key list
4241
EOF
4342
sensitive = true
43+
default = 0
4444

4545
validation {
46-
condition = var.step2_do_admin_ssh_key >= 0
46+
condition = var.ssh_key_id >= 0
4747
error_message = "Invalid Digital Ocean SSH key ID, a number is required."
4848
}
4949
}
@@ -291,11 +291,11 @@ resource "digitalocean_droplet" "workspace" {
291291
coder_agent_token = coder_agent.main.token
292292
})
293293
# Required to provision Fedora.
294-
ssh_keys = var.step2_do_admin_ssh_key > 0 ? [var.step2_do_admin_ssh_key] : []
294+
ssh_keys = var.ssh_key_id > 0 ? [var.ssh_key_id] : []
295295
}
296296

297297
resource "digitalocean_project_resources" "project" {
298-
project = var.step1_do_project_id
298+
project = var.project_uuid
299299
# Workaround for terraform plan when using count.
300300
resources = length(digitalocean_droplet.workspace) > 0 ? [
301301
digitalocean_volume.home_volume.urn,

0 commit comments

Comments
 (0)