Terraform (henceforth TF) is an open-source infrastructure as code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. Terraform codifies cloud APIs into declarative configuration files. For this page we refer to this GitHub project.
Requirements
The necessary prerequisites are as follows:
- Install TF;
- Install Ansible;
- you already have a floating IP pool created;
- you have security groups enabled;
- you have a pair of keys generated that can be used to secure the new hosts.
Configuration
Inventory files
Create a directory for your cluster, mycluster
for istance, by copying the existing sample-inventory
and linking thehosts
script, used to build the inventory based on TF state (this will be the base for subsequent Terraform commands).
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
cp -LRp contrib/terraform/openstack/sample-inventory inventory/mycluster
cd inventory/mycluster
ln -s ../../contrib/terraform/openstack/hosts
ln -s ../../contrib |
OpenStack access and credentials
TF supports various authentication methods for OpenStack. The recommended authentication method is to describe credentials in a YAML fileclouds.yaml
, that can be stored in the current directory.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# Find the "auth_url" and "project_id" parameters in the OpenStack "Project/API Access" tab clouds: openstack: auth: auth_url: https://cloud-api-pub.cr.cnaf.infn.it:5000/v3/ username: "yourUser" project_name: "yourProject" project_id: d2b42ee4145849819b41a9d8794a111d user_domain_id: "default" password: "yourP4ssw0rd" region_name: "sdds" interface: "public" identity_api_version: 3 |
If you have multiple clouds defined in your clouds.yaml
file you can choose the one you want to use with the environment variable OS_CLOUD
.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# Insert this line in the .bashrc file for variable persistence
export OS_CLOUD=openstack
# To apply the changes
$ source .bashrc |
Cluster variables
The construction of the cluster is driven by values found in ../../contrib/terraform/openstack/
variables.tf
. You can consult this file to find out which variables are available for configuration, accompanied by a brief description, which values they accept and their defaults. For your cluster, edit cluster.tfvars
.