How to provision your private environment with Terraform on SkyAtlas

Onur Ozkan
3 min readDec 6, 2019

--

This article will walk you through to manage your SkyAtlas project with Terraform. Terraform is a quite powerful and skilled automation tool for infrastructure management. In this example, we will use it for managing OpenStack environment but you can also use Terraform for pretty much any other Cloud Provider like AWS or GCP.

Not surprisingly, we need to install Terraform first, you can find how to install it on Linux below but still, recommend to check Terraform Website for the latest way(s) of installation.

$ wget https://releases.hashicorp.com/terraform/0.12.16/terraform_0.12.16_linux_amd64.zip$ unzip terraform_0.12.16_linux_amd64.zip$ sudo mv terraform /usr/local/bin/

For identity verification we’ll use an RC file, in order to get that file login to SkyAtlas dashboard.

Then navigate to the Project tab on the drop-down menu, open the Compute tab and click Access & Security. On the API Access tab, click Download OpenStack RC File and save the file (both versions supported by Terraform). The filename will be the form of PROJECT-openrc.sh where PROJECT is the name of the project for which you downloaded the file.

When you source the file it will ask your SkyAtlas account password, after you type in your password correctly environment variables and your credentials will be set for your current shell.

$ source PATH_OF_THE_RC_FILE.sh

Now it’s time to get Terraform configuration files from GitLab, these files contain platform-ready example configs which all the variables are compatible with OpenStack RC file.

$ git clone https://gitlab.com/itsmeoz/skyatlas_compute_cluster.git

When it’s done, navigate the folder you want to deploy

$ cd instance_with_lb

In this given example below, we’ll deploy two load-balancers, two separate networks and two different types of instances connected to those networks.

Terraform needs to download provider plugins first.

$ terraform init

Before the initial deployment, it would be nice to have a plan right? Terraform plan command generates an execution plan which will give you output for actions that will be performed.

Just copy and paste the command below, it will work with your rc file if you source it already.

$ terraform plan \-var os_username=$OS_USERNAME \-var os_project_name=$OS_PROJECT_NAME \-var os_password_input=$OS_PASSWORD_INPUT \-var os_auth_url=$OS_AUTH_URL \-var os_region_name=$OS_REGION_NAME \-var ssh_key_file=~/.ssh/id_rsa

Note: the command above assumes you have a ssh-key files under your home directory which is ‘~/.ssh/id_rsa’ if it’s not or you might want to use different key file, you should change the path.

If you’re satisfied with your Terraform plan output, you’re ready to deploy your environment.

Warning: Following steps may create resources which cost you money.

If you ready to deploy your environment simply run this command:

$ terraform apply \-var os_username=$OS_USERNAME \-var os_project_name=$OS_PROJECT_NAME \-var os_password_input=$OS_PASSWORD_INPUT \-var os_auth_url=$OS_AUTH_URL \-var os_region_name=$OS_REGION_NAME \-var ssh_key_file=~/.ssh/id_rsa

When you’re done, you can wipe out all of your infrastructure:

$ terraform destroy \-var os_username=$OS_USERNAME \-var os_project_name=$OS_PROJECT_NAME \-var os_password_input=$OS_PASSWORD_INPUT \-var os_auth_url=$OS_AUTH_URL \-var os_region_name=$OS_REGION_NAME \-var ssh_key_file=~/.ssh/id_rsa

Warning: Be aware that terraform destroy command will not destroy your volumes for safety reasons, you can change the code or you could manually delete all the volumes you created if you don’t need them.

The video shows the steps and possible errors you might come across during the process.

--

--