Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit31077b9

Browse files
spikecurtiskylecarbs
authored andcommitted
feat: Authenticate Digital Ocean via environment variable (#2051)
* Digital Ocean example uses environment variable authSigned-off-by: Spike Curtis <spike@coder.com>
1 parentae46463 commit31077b9

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

‎examples/templates/do-linux/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ This is an example for deploying workspaces as Digital Ocean Droplets.
1010

1111
##Requirements
1212

13-
- Digital Ocean Personal Access Token (PAT)
1413
- Digital Ocean Project ID (e.g.`doctl projects list`)
1514
- Remove`variable "step2_do_project_id"` and`resource "digitalocean_project_resources" "project"` if you don't want project association.
1615
- (Optional) Digital Ocean SSH key ID (e.g.`doctl compute ssh-key list`)
1716
- Only required for Fedora images to work.
17+
18+
##Authentication
19+
20+
This template assumes that coderd is run in an environment that is authenticated
21+
with Digital Ocean. Obtain a
22+
[Digital Ocean Personal Access Token](https://cloud.digitalocean.com/account/api/tokens) and set
23+
the environment variable`DIGITALOCEAN_TOKEN` to the access token before starting coderd. For
24+
other ways to authenticate
25+
[consult the Terraform docs](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs).

‎examples/templates/do-linux/main.tf

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@ terraform {
1111
}
1212
}
1313

14-
variable"step1_do_token" {
15-
type=string
16-
description="Enter token (see documentation at https://docs.digitalocean.com/reference/api/create-personal-access-token/)"
17-
sensitive=true
18-
19-
validation {
20-
condition=length(var.step1_do_token)==71&&substr(var.step1_do_token,0,4)=="dop_"
21-
error_message="Invalid Digital Ocean Personal Access Token."
22-
}
23-
}
24-
25-
variable"step2_do_project_id" {
14+
variable"step1_do_project_id" {
2615
type=string
2716
description=<<-EOF
2817
Enter project ID
@@ -32,17 +21,17 @@ variable "step2_do_project_id" {
3221
sensitive=true
3322

3423
validation {
35-
condition=length(var.step2_do_project_id)==36
24+
condition=length(var.step1_do_project_id)==36
3625
error_message="Invalid Digital Ocean Project ID."
3726
}
3827
}
3928

40-
variable"step3_do_admin_ssh_key" {
29+
variable"step2_do_admin_ssh_key" {
4130
type=number
4231
description=<<-EOF
4332
Enter admin SSH key ID (some Droplet images require an SSH key to be set):
4433
45-
Can be set tozero.
34+
Can be set to"0" for no key.
4635
4736
Note: Setting this to zero will break Fedora images and notify root passwords via email.
4837
@@ -51,7 +40,7 @@ variable "step3_do_admin_ssh_key" {
5140
sensitive=true
5241

5342
validation {
54-
condition=var.step3_do_admin_ssh_key>=0
43+
condition=var.step2_do_admin_ssh_key>=0
5544
error_message="Invalid Digital Ocean SSH key ID, a number is required."
5645
}
5746
}
@@ -98,7 +87,8 @@ variable "region" {
9887

9988
# Configure the DigitalOcean Provider
10089
provider"digitalocean" {
101-
token=var.step1_do_token
90+
# Recommended: use environment variable DIGITALOCEAN_TOKEN with your personal access token when starting coderd
91+
# alternatively, you can pass the token via a variable.
10292
}
10393

10494
data"coder_workspace""me" {}
@@ -130,12 +120,12 @@ resource "digitalocean_droplet" "workspace" {
130120
coder_agent_token= coder_agent.dev.token
131121
})
132122
# Required to provision Fedora.
133-
ssh_keys=var.step3_do_admin_ssh_key>0? [var.step3_do_admin_ssh_key]: []
123+
ssh_keys=var.step2_do_admin_ssh_key>0? [var.step2_do_admin_ssh_key]: []
134124
}
135125

136126
# Temporarily disabled because it breaks SSH. (https://github.com/coder/coder/issues/1750)
137127
# resource "digitalocean_project_resources" "project" {
138-
# project = var.step2_do_project_id
128+
# project = var.step1_do_project_id
139129
# # Workaround for terraform plan when using count.
140130
# resources = length(digitalocean_droplet.workspace) > 0 ? [
141131
# digitalocean_volume.home_volume.urn,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp