10

DISCOUNT

REGISTER NOW

How to Build a Custom Environment with Terraform in OpenStack?

          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 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 SkyAtlas dashboard.

mceclip0.png

Then navigate to 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. The filename will be the form PROJECT-openrc.sh where PROJECT is the name of the project for which you downloaded the file.

mceclip1.png

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 THE_RC_FILE.sh 

Now it’s time to get Terraform configuration files from GitLab, this files contains 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 and use the command below to deploy your environment.

$ cd  instance_with_lb

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

 

Before you start using Terraform, it needs to download provider plugins.

$ 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 an output for actions will be perform.

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 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 should manually delete all the volumes you created if you don’t need them.

 

 

Have more questions? Submit a request
Powered by Zendesk