Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Terraform w/ Openstack

You can use the Openstack Provider with Tofu/Terraform to manage the lab environment with IaC.

Docs for the provider itself can be found here: Terraform Registry

You will need to source the OpenRC file, you can check how to do that here.

Here’s an example of a basic setup (Network, Subnet, Router) with the Openstack provider in Terraform where all openstack provider options are pulled from the environment which we sourced with the OpenRC file:

provider "openstack" {
}

resource "openstack_networking_network_v2" "net-1" {
  name           = "net-1"
}

resource "openstack_networking_subnet_v2" "subnet-1" {
  name       = "subnet-1"
  network_id = openstack_networking_network_v2.net-1.id
  cidr       = "10.10.10.0/24"
  ip_version = 4
}

resource "openstack_networking_router_v2" "rtr-1" {
  name                = "rtr-1"
  external_network_id = "9d702c95-0330-4108-b93d-001e7c4cd00d"
}

resource "openstack_networking_router_interface_v2" "rtr-subnet-1" {
  router_id = openstack_networking_router_v2.rtr-1.id
  subnet_id = openstack_networking_subnet_v2.subnet-1.id
}

Run the following to get everything initialized properly (if you haven’t do it already) and then apply:

terraform init
terraform apply