Skip to content

Commit 4bba315

Browse files
carmstrongSeth Goings
authored andcommitted
ref(contrib): use Terraform for DO provisioning
This lets us use Terraform to provision and manage Deis deployments on Digital Ocean. - make Terraform grab coreos user-data file relative to .tf file - include a better README.md with rigger references - add descriptions to all variables that will prompt the user - add rigger support for Digital Ocean
1 parent f9cd978 commit 4bba315

10 files changed

Lines changed: 116 additions & 108 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ contrib/gce/gce-user-data
8585
/tests/bin/tmp
8686
!/tests/bin/accept/lib
8787
!/tests/bin/accept/commands
88+
89+
# Terraform
90+
*.tfstate*

contrib/digitalocean/check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail -o nounset

contrib/digitalocean/config.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export DEIS_TEST_DOMAIN="xip.io"
2+
export DO_TOKEN
3+
export DO_SSH_FINGERPRINT
4+
5+
prompt "What Digital Ocean token should I use?" DO_TOKEN
6+
prompt "What Digital Ocean ssh fingerprint should I use?" DO_SSH_FINGERPRINT
7+
8+
export TF_VAR_deis_root="${DEIS_ROOT}"
9+
export TF_VAR_token="${DO_TOKEN}"
10+
export TF_VAR_ssh_keys="${DO_SSH_FINGERPRINT}"
11+
export TF_VAR_prefix="deis-${DEIS_ID}"
12+
13+
rigger-save-vars DEIS_TEST_DOMAIN \
14+
DO_TOKEN \
15+
DO_SSH_FINGERPRINT \
16+
TF_VAR_deis_root \
17+
TF_VAR_prefix \
18+
TF_VAR_ssh_keys \
19+
TF_VAR_token

contrib/digitalocean/create

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail -o nounset
4+
5+
terraform apply
6+
7+
export DEISCTL_TUNNEL="$(terraform output ip)"
8+
export DEIS_TEST_DOMAIN="${DEISCTL_TUNNEL}.xip.io"
9+
10+
rigger-save-vars DEISCTL_TUNNEL \
11+
DEIS_TEST_DOMAIN
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
provider "digitalocean" {
2+
token = "${var.token}"
3+
}
4+
5+
resource "digitalocean_droplet" "deis" {
6+
count = "${var.instances}"
7+
image = "coreos-stable"
8+
name = "${var.prefix}-${count.index+1}"
9+
region = "${var.region}"
10+
size = "${var.size}"
11+
backups = "False"
12+
ipv6 = "False"
13+
private_networking = "True"
14+
ssh_keys = ["${var.ssh_keys}"]
15+
user_data = "${file("${path.module}/../coreos/user-data")}"
16+
}
17+
18+
output "msg" {
19+
value = "Your hosts are ready to go! Continue following the documentation to install and start Deis. Your hosts are: ${join(", ", digitalocean_droplet.deis.*.ipv4_address)}"
20+
}
21+
22+
output "ip" {
23+
value = "${digitalocean_droplet.deis.0.ipv4_address}"
24+
}

contrib/digitalocean/destroy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail -o nounset
4+
5+
terraform destroy -force

contrib/digitalocean/install

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail -o nounset
4+
5+
rigger-install-terraform

contrib/digitalocean/provision-do-cluster.sh

Lines changed: 0 additions & 73 deletions
This file was deleted.

contrib/digitalocean/variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
variable "instances" {
2+
default = "3"
3+
}
4+
5+
variable "prefix" {
6+
default = "deis"
7+
}
8+
9+
variable "region" {
10+
default = "sfo1"
11+
}
12+
13+
variable "size" {
14+
default = "8GB"
15+
}
16+
17+
variable "ssh_keys" {
18+
description = "The ssh fingerprint of the ssh key you'll be using"
19+
}
20+
21+
variable "token" {
22+
description = "Your Digital Ocean auth token"
23+
}

docs/installing_deis/digitalocean.rst

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ To complete this guide, you must have the following:
2020
- A domain to point to the cluster
2121
- The ability to provision at least 3 DigitalOcean Droplets that are 4GB or greater
2222

23-
In order to provision the cluster, we will need to install a couple of administrative tools.
24-
`docl`_ is a convenience tool to help provision DigitalOcean Droplets. We will also require the
25-
`Deis Control Utility`_, which will assist us with installing, configuring and managing the Deis
26-
platform.
23+
Additionally, we'll need to install `Terraform`_ to do the heavy lifting for us.
24+
2725

2826
Check System Requirements
2927
-------------------------
@@ -37,6 +35,8 @@ Generate SSH Key
3735

3836
.. include:: ../_includes/_generate-ssh-key.rst
3937

38+
Upload this key to DigitalOcean so we can use it for the rest of the provisioning
39+
process.
4040

4141
Generate a New Discovery URL
4242
----------------------------
@@ -47,42 +47,29 @@ Generate a New Discovery URL
4747
Create CoreOS Droplets
4848
----------------------
4949

50-
Now that we have the user-data file, we can provision some Droplets. We've made this process simple
51-
by supplying a script that does all the heavy lifting for you. If you want to provision manually,
52-
however, start by uploading the SSH key you wish to use to log into each of these servers. After
53-
that, create at least three Droplets with the following specifications:
50+
The only other pieces of information we'll need are your DigitalOcean API token
51+
and the fingerprint of your SSH key, both of which can be obtained from the
52+
DigitalOcean interface.
53+
54+
From the source code root directory, invoke Terraform:
5455

55-
- All Droplets deployed in the same region
56-
- Region must have private networking enabled
57-
- Region must have User Data enabled. Supply the user-data file here
58-
- Select CoreOS Stable channel
59-
- Select your SSH key from the list
56+
.. code-block:: console
6057
61-
If private networking is not available in your region, swap out ``$private_ipv4`` with
62-
``$public_ipv4`` in the user-data file.
58+
$ terraform apply -var 'token=a1b2c3d3e4f5' \
59+
-var 'ssh_keys=c1:d3:a2:b4:e4:f5' \
60+
-var 'region=nyc3' \
61+
-var 'prefix=deis' \
62+
-var 'instances=3' \
63+
-var 'size=8GB' \
64+
contrib/digitalocean
6365
64-
If you want to use the script:
6566
66-
.. code-block:: console
67+
Note that only ``token`` and ``ssh_keys`` are required - if unset, the other variables
68+
will default to 3 hosts in the ``sfo1`` region with a size of 8GB and a prefix
69+
of ``deis``. Additionally, ``ssh_keys`` can be just one key, or a comma-separated
70+
list of keys to be added to the hosts for the ``core`` user.
6771

68-
$ gem install docl
69-
$ docl authorize
70-
$ docl upload_key deis ~/.ssh/deis.pub
71-
$ # retrieve your SSH key's ID
72-
$ docl keys
73-
deis (id: 12345)
74-
$ # retrieve the region name
75-
$ docl regions --metadata --private-networking
76-
Amsterdam 2 (ams2)
77-
Amsterdam 3 (ams3)
78-
Frankfurt 1 (fra1)
79-
London 1 (lon1)
80-
New York 3 (nyc3)
81-
San Francisco 1 (sfo1)
82-
Singapore 1 (sgp1)
83-
$ ./contrib/digitalocean/provision-do-cluster.sh nyc3 12345 4GB
84-
85-
Which will provision 3 CoreOS nodes for use.
72+
The ``region`` option must specify a region with private networking.
8673

8774
Configure DNS
8875
-------------
@@ -154,3 +141,4 @@ start installing the platform.
154141
.. _`Deis Control Utility`: https://github.com/deis/deis/tree/master/deisctl#readme
155142
.. _`DNS control panel`: https://cloud.digitalocean.com/domains
156143
.. _`this tutorial`: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-host-name-with-digitalocean
144+
.. _`Terraform`: https://terraform.io/

0 commit comments

Comments
 (0)