User:Bking/Notes/Terraform on WMCS Initial Setup
Why?
Now that Terraform is compatibile with WMCS (Thanks Taavi and WMCS team), we can use this tool to quickly provision and configure servers. Note: this guide presumes that you're using a UNIX-like OS, and have some degree of familiarity with the terminal.
How to Configure
Software
The following software should be installed on your desktop:
- Terraform
- Openstack CLI
Credentials
- Generate Openstack API application credentials.
- From your WMCS Horizon API access page, click "Download Openstack RC File" and select OpenStack RC File.
- Save the file on your computer. It contains a secret, so be sure to set the correct permissions. Let's say we save it to
~/.nova.conf
- From your terminal, type
source ~/.nova.conf
and hit Enter. This adds a lot of Openstack-related environment variables to your terminal session. Both Openstack CLI and the Terraform Openstack provider will automatically consume these variables, which means you don't need to add specific data about your cloud account, username, password, etc into your Terraform plans.
Verifying Credentials
If you want to verify that the environment variables are set properly, run openstack flavor list
from your terminal. You should get a response containing the flavors offered by the Openstack Compute API. If not, you may need to repeat step 4. You can check for the environment variables by typing env | grep OS
from your terminal. Example output:
OS_AUTH_URL=https://openstack.eqiad1.wikimediacloud.org:25000/v3 OS_APPLICATION_CREDENTIAL_SECRET=[redact] OS_APPLICATION_CREDENTIAL_ID=[redact] OS_AUTH_TYPE=v3applicationcredential OS_APPLICATION_CREDENTIAL_NAME=bking_search_dp OS_IDENTITY_API_VERSION=3
Start your terraform repo
On your desktop, create a new directory and navigate to the new directory in your terminal. Within the directory, create a file called main.tf
with the following content:
terraform {
required_version = ">= 1.3.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.48.0"
}
}
}
Initialize the Terraform repository by typing terraform init
and hitting Enter. You should get a response similar to this (edited for length):
Initializing the backend... Initializing provider plugins... - Finding terraform-provider-openstack/openstack versions matching "~> 1.48.0"... - Installing terraform-provider-openstack/openstack v1.48.0... - Installed terraform-provider-openstack/openstack v1.48.0 (self-signed, key ID 4F80527A391BEFD2) Terraform has been successfully initialized!
Congratulations, you're ready to Terraform!