OpenStack Provider

The OpenStack Provider allows Terraform to manage infrastructure in OpenStack environments, including compute instances, networks, volumes, and identity services. This provider is ideal for automating cloud infrastructure on private or public OpenStack deployments.

Key Features:

  • Provision compute instances, including key pairs and security groups.
  • Configure networking resources such as subnets, routers, and floating IPs.
  • Manage block storage volumes and object storage containers.
  • Automate identity and access management with users, groups, and roles.

Example Use Case: Creating a Compute Instance
Here’s how to create an OpenStack compute instance using Terraform:

provider "openstack" {
  auth_url    = "https://openstack.example.com:5000/v3"
  tenant_name = "example-tenant"
  username    = "example-user"
  password    = "example-password"
  region      = "RegionOne"
}

resource "openstack_compute_instance_v2" "example" {
  name            = "example-instance"
  image_name      = "Ubuntu 20.04"
  flavor_name     = "m1.small"
  key_pair        = "example-keypair"
  security_groups = ["default"]

  network {
    name = "public"
  }
}

What’s Happening Here?

  • The provider block configures Terraform to connect to the OpenStack environment with the specified credentials.
  • The openstack_compute_instance_v2 resource creates a compute instance named example-instance with the Ubuntu 20.04 image and the m1.small flavor.
  • The instance is associated with a key pair and added to the default security group.
  • The instance is connected to the public network.

Advanced Tip:
Add a floating IP to the compute instance for external connectivity:

resource "openstack_networking_floatingip_v2" "example" {
  pool = "public"
}

resource "openstack_compute_floatingip_associate_v2" "example" {
  floating_ip = openstack_networking_floatingip_v2.example.address
  instance_id = openstack_compute_instance_v2.example.id
}

This configuration allocates a floating IP from the public pool and associates it with the compute instance.