Skip to content

Terraform Installation

Terraform is an infrastructure-as-code tool that lets you define, provision, and manage cloud resources through declarative configuration files. With the OpenStack provider, Terraform can deploy VMs, networks, volumes, security groups, and more — all version-controlled and repeatable.

This chapter describes how to install Terraform and configure it for the OpenStack platform.

Prerequisites

  • Basic knowledge of the Linux operating system (shell)
  • Access to a running Linux VM or workstation (Ubuntu/Debian in our example) with an open port (Egress 443) to the OpenStack API
  • Application Credentials (clouds.yaml) — see Application Credentials

The steps to be performed are:

  • Installation of the Terraform binary
  • Configuration of the OpenStack provider
  • Initialization and a test run

Note

Terraform reads the same clouds.yaml file as the OpenStack CLI. Make sure it is placed at ~/.config/openstack/clouds.yaml before you start.

Steps:

0) Install Terraform (Ubuntu / Debian)

Add the HashiCorp APT repository and install Terraform:

wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

sudo apt update
sudo apt install -y terraform

Verify the installation:

terraform -version

Alternative: manual binary download

For non-Debian systems, download the binary from https://developer.hashicorp.com/terraform/downloads and place it in your PATH.

1) Configure the OpenStack provider

Create a working directory for your Terraform project and add a provider.tf file:

mkdir -p ~/terraform-openstack && cd ~/terraform-openstack
vim provider.tf
terraform {
  required_providers {
    openstack = {
      source  = "terraform-provider-openstack/openstack"
      version = "~> 1.53"
    }
  }
}

provider "openstack" {
  cloud = "openstack"
}

The cloud = "openstack" value must match the top-level key in your clouds.yaml. Terraform uses the same file as the OpenStack CLI — no separate credentials are needed.

2) Initialize the project

terraform init

Terraform downloads the OpenStack provider plugin and creates a .terraform/ directory. You should see a message confirming successful initialization.

3) Test with a minimal resource

Create a main.tf that reads an image list (read-only, no resources created):

data "openstack_images_image_v2" "ubuntu" {
  name        = "Ubuntu 24.04"
  most_recent = true
}

output "ubuntu_image_id" {
  value = data.openstack_images_image_v2.ubuntu.id
}

Run a plan — this validates connectivity and authentication without creating anything:

terraform plan

If everything is configured correctly, Terraform connects to the OpenStack API, resolves the Ubuntu 24.04 image, and prints its ID.

Congratulations, your Terraform setup is operational!

For full deployment examples (VMs, volumes), see: Infrastructure as Code

For more information on the OpenStack provider, refer to: Terraform OpenStack Provider Documentation