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:
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?
provider block configures Terraform to connect to the OpenStack environment with the specified credentials.openstack_compute_instance_v2 resource creates a compute instance named example-instance with the Ubuntu 20.04 image and the m1.small flavor.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.