Using Terraform to Install DevStack on DigitalOcean
There are a few times where having a persistent OpenStack lab on a shared infrastructure is handy. I’ve been revisiting DevStack a lot more lately in order to help a few folks get their labs up and running. DevStack is the OpenStack project which lets you run non-production OpenStack using either a single or a multi-node configuration. Running on DigitalOcean means that I can have a lab that can spin up quickly (about 40 minutes) and also lets me find another handy use for Terraform.
NOTE: This uses an 80$/month DigitalOcean droplet, so please keep that in mind as you experiment.
Requirements for this are:
- A DigitalOcean account
- Terraform configured for your DigitalOcean API token (see https://turbonomic.com/blog/on-technology/getting-started-with-terraform-for-digital-ocean/ )
- SSH fingerprint information for your DigitalOcean account (see http://discoposse.com/2017/02/08/adding-ssh-access-for-digitalocean-when-using-terraform/ )
- 45-60 minutes of build time
Getting the Code
All of the scripts and configuration are on GitHub for free use and are also open for contributions and updates if you see anything that you’re keen to add to. Remember that Terraform uses state files to manage your environment, so when you pull down the GitHub repo and launch your environment, it will create the
.tfstatebackup files after you launch for the first time.
Grab the code using
git clone https://github.com/discoposse/terraform-samples to bring it down locally:
Change directory into the
/terraform-samples/DigitalOcean/devstack folder where we will be working:
Make sure you have the environment variables setup including the DigitalOcean API token, SSH key file locations, and your SSH fingerprint. These can be exported into your environment using a script or as one-off commands:
The process that is run by the code is to:
- Pull the DigitalOcean environment needs (API and SSH info)
- Launch an 8 GB RAM droplet in the NYC2 region and attach your SSH fingerprint
- Insert the DevStack build script (files/devstack-install.sh) as a cloud-init script
Those are the pre-requirements. Now it’s time to get started!
Launching the DevStack Build on DigitalOcean with Terraform
It’s always good to use a health check flow of your Terraform builds. Start by validating, running the plan, and then launching. This ensures that you have a good environment configuration and the process should work smoothly.
No news is good news. The code validated fine and we are ready to run the
terraform plan command to see what will transpire when we launch the build:
We can see a single droplet will be created because we have nothing to start with. There are a number of parameters that are dynamic and will be populated when the environment launches. Time to go for it!
This is where you need a little bit of patience. The build takes approximately 45-60 minutes. We know the IP address of the environment because we requested it via the Terraform outputs. You can confirm this at any time by running the
terraform output command:
Checking the DevStack Install Progress using the Cloud-Init Log
Let’s connect via SSH to our DigitalOcean droplet so we can monitor the build progress. We use the build script as a cloud-init script so that it launches as root during the deployment. This means you can keep track of the results using the
/var/log/cloud-init.log and the
Install completion is indicated by a set of log results like this:
Let’s try it out to confirm using the OpenStack Horizon dashboard URL as indicated in the cloud-init output. There are two accounts created by the script which are
demo, both of which have
secret-do as the default password.
NOTE: Please change your OpenStack passwords right away! These are simple, plain-text passwords that are packaged with the build and you are vulnerable to attack
That gets us up and running. You are incurring charges as long as the environment is up, so when you’re ready to bring the environment down and destroy the droplet, it’s as easy as it was to launch it.
Destroying the DevStack DigitalOcean Build Using Terraform Destroy
In just two quick words and a confirmation we can remove all of the environment:
Just like that we have installed an all-in-one OpenStack DevStack node on DigitalOcean and learned another nifty way to leverage Hashicorp Terraform to do it.