Terraform
Terraform providers openstack links:

In this guide we will see how to use Terraform to manage an OpenStack infrastructure on the UNIQCLOUD.
Prerequisites
To get started you need some prerequisites:
- Install HashiCorp Terraform or OpenTofu
- Download your Openstack configuration from the Openstack Dashboard UUNQCloud Dashboard and use Openstack RC file Openstack-login
Following code has been tested in UNIQCloud with terraform 1.7 and Openstack terraform provider ~> 3.0.0
Configure Credentials in Terraform Provider for Uniqcloud
Traditionally, the OpenStack tools were configured using a set of environment variables (OS_AUTH_URL, OS_USERNAME, etc.), usually delivered in the format of a simple shell script that can be sourced into your current environment. While this works, it becomes hard to manage if you are working with multiple OpenStack environments.
The clouds.yaml configuration file was developed as an alternative mechanism for storing your OpenStack credentials. Follow the procedure according to your actual setup :
- Use openRC
- Cloud.yaml
- Using Environment Variables
This is an example of main.tf for use Keystone v3
# Define required providers
terraform {
required_version = ">= 1.7.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 3.0.0"
}
}
}
# Configure the OpenStack Provider
provider "openstack" {
auth_url = "https://keystone.api.eu-vlc.uniccloud.org:5000/v3"
user_name = "name-user"
password = var.openstack_password
project_id = "id-project"
user_domain_name = "name-domain"
}
If UNICC CA is not installed in the laptop/server running terraform you must configure it in the terrform provider section.
cacert_file = local-file-containing-cert.pem
If you don't have access to the certicate file, requested to support.
# Define required providers
terraform {
required_version = ">= 1.7.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 3.0.0"
}
}
}
# Configure the OpenStack Provider
provider "openstack" {
cloud = "cloud.yaml"
}
Example Cloud.yaml
clouds:
uniccloud:
auth:
auth_url: https://keystone.api.eu-vlc.uniccloud.org:5000/v3
username: name_user
password: pass_user
project_id: project_id
user_domain_name: domain_name
region_name: Valencia
interface: public
identity_api_version: 3
If UNICC CA is not installed in the laptop/server running terraform you must configure it in the terrform provider section.
cacert_file = local-file-containing-cert.pem
If you don't have access to the certicate file, requested to support.
# Define required providers
terraform {
required_version = ">= 1.7.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 3.0.0"
}
}
}
# Configure the OpenStack Provider
provider "openstack" {}
Export Environment Variables
export OS_AUTH_URL="https://keystone.api.eu-vlc.uniccloud.org:5000/v3"
export OS_REGION_NAME=Valencia
export OS_USERNAME="example-svc-user"
export OS_PASSWORD="xxxxx"
export OS_DOMAIN_ID=67ffc820856348deaca7ad528b0098f8
export OS_PROJECT_ID=7143a442f4ec0b0aa9c86c8c845e5
If UNICC CA is not installed in the laptop/server running terraform you must configure it in the terrform provider section.
export OS_CACERT = local-file-containing-cert.pem
If you don't have access to the certicate file, requested to support.
Use Remote Tfstate
Store your Terraform state securely in OpenStack using Rados Gateway S3 API for remote tfstate management.
- Create a swift container as explained here
- Create ec2 compatible credentials following this guide
- Export credentials configured in the previous step.
export AWS_ACCESS_KEY_ID="b3..."
export AWS_SECRET_ACCESS_KEY="df..."
- Configure your backend.tfvars file.
backend.tfvars
bucket = "my-example-tfstate"
key = "tfstates/mykey"
region = "Valencia"
endpoint = "https://radosgw.api.eu-vlc.uniccloud.org"
- Configure the following settings in the terraform backend.
terraform {
backend "s3" {
skip_credentials_validation = true
skip_region_validation = true
skip_requesting_account_id = true
skip_s3_checksum = true
use_path_style = true
}
}
- Execute the terraform init command.
terraform init --backend-config=backend.tfvars
Following code has been tested in UNIQCloud with terraform 1.7 and Openstack terraform provider ~> 3.0.0 Due to a known issue in Terraform 1.11.2+, the skip_s3_checksum option may fail when using non-AWS S3 backends (like Ceph RadosGW).
To fix this, set these environment variables before running Terraform:
AWS_REQUEST_CHECKSUM_CALCULATION=when_required AWS_RESPONSE_CHECKSUM_VALIDATION=when_required
This ensures checksums are only calculated when necessary, avoiding conflicts.