Skip to content

Commit c8100da

Browse files
author
Seth Goings
committed
Merge pull request #4694 from sgoings/digitalocean-improvements
feat(contrib/digitalocean): improve Digital Ocean provisioning workflow
2 parents 8ac36e8 + 7c13eef commit c8100da

4 files changed

Lines changed: 70 additions & 8 deletions

File tree

contrib/digitalocean/config.sh

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,76 @@ export DEIS_TEST_DOMAIN="xip.io"
22
export DO_TOKEN
33
export DO_SSH_FINGERPRINT
44

5-
prompt "What Digital Ocean token should I use?" DO_TOKEN
6-
prompt "What Digital Ocean ssh fingerprint should I use?" DO_SSH_FINGERPRINT
5+
function check-do-token {
6+
if [ ! -z ${1} ]; then
7+
local token="${1}"
8+
curl --fail -X GET -H "Authorization: Bearer ${token}" \
9+
"https://api.digitalocean.com/v2/account" &> /dev/null
10+
else
11+
return 1
12+
fi
13+
}
14+
15+
function check-do-ssh-key {
16+
local token="${1}"
17+
local ssh_fingerprint="${2}"
18+
19+
if [ ! -z ${ssh_fingerprint} ]; then
20+
curl --fail \
21+
-X GET \
22+
-H \
23+
"Authorization: Bearer ${token}" \
24+
"https://api.digitalocean.com/v2/account/keys/${ssh_fingerprint}" &> /dev/null
25+
else
26+
return 1
27+
fi
28+
}
29+
30+
while true; do
31+
password-prompt "What DigitalOcean token should I use?" DO_TOKEN
32+
33+
if ! check-do-token "${DO_TOKEN:-}"; then
34+
rerun_log error "Couldn't login to DigitalOcean using this API token. :-("
35+
unset DO_TOKEN
36+
else
37+
rerun_log info "Successfully logged into DigitalOcean!"
38+
break
39+
fi
40+
done
41+
42+
while true; do
43+
ssh-private-key-prompt "What private SSH key should I use when creating DigitalOcean droplets?" SSH_PRIVATE_KEY_FILE
44+
45+
export DO_SSH_FINGERPRINT="$(ssh-fingerprint "${SSH_PRIVATE_KEY_FILE}")"
46+
47+
if ! check-do-ssh-key "${DO_TOKEN}" "${DO_SSH_FINGERPRINT:-}"; then
48+
rerun_log error "Couldn't find the fingerprint for this key in DigitalOcean."
49+
50+
cat <<EOF
51+
Upload the public key by pressing the "Add SSH Key" button on
52+
your DigitalOcean security page:
53+
54+
https://cloud.digitalocean.com/settings/security
55+
56+
Or pick a different key...
57+
58+
EOF
59+
60+
unset SSH_PRIVATE_KEY_FILE
61+
else
62+
rerun_log info "This SSH key is correctly configured for use with DigitalOcean!"
63+
break
64+
fi
65+
done
66+
67+
rigger-log "DO_SSH_FINGERPRINT set to ${DO_SSH_FINGERPRINT}"
768

869
export TF_VAR_deis_root="${DEIS_ROOT}"
9-
export TF_VAR_token="${DO_TOKEN}"
1070
export TF_VAR_ssh_keys="${DO_SSH_FINGERPRINT}"
1171
export TF_VAR_prefix="deis-${DEIS_ID}"
1272

1373
rigger-save-vars DEIS_TEST_DOMAIN \
14-
DO_TOKEN \
1574
DO_SSH_FINGERPRINT \
1675
TF_VAR_deis_root \
1776
TF_VAR_prefix \
18-
TF_VAR_ssh_keys \
19-
TF_VAR_token
77+
TF_VAR_ssh_keys

contrib/digitalocean/create

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
set -eo pipefail -o nounset
44

5-
terraform apply
5+
export TF_VAR_token="${DO_TOKEN}"
6+
7+
terraform apply | grep --line-buffered -v user_data
68

79
export DEISCTL_TUNNEL="$(terraform output ip)"
810
export DEIS_TEST_DOMAIN="${DEISCTL_TUNNEL}.xip.io"

contrib/digitalocean/destroy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
set -eo pipefail -o nounset
44

5+
export TF_VAR_token="${DO_TOKEN}"
6+
57
terraform destroy -force

contrib/digitalocean/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ variable "ssh_keys" {
1919
}
2020

2121
variable "token" {
22-
description = "Your Digital Ocean auth token"
22+
description = "Your DigitalOcean auth token"
2323
}

0 commit comments

Comments
 (0)