How to automate a MicroCloud test deployment with Terraform¶
This guide shows you how to automatically deploy a MicroCloud test environment using Terraform and the LXD provider. The Terraform configuration replicates the same setup as in our multi-member tutorial, which uses four VMs on a single physical machine for the MicroCloud cluster members. It automates all the manual steps from that tutorial, including VM creation, disk provisioning, network configuration, and MicroCloud initialization.
For production deployments, use physical machines instead of VMs and review the Requirements for proper hardware specifications.
Note
This Terraform configuration creates the same infrastructure as the manual multi-member tutorial. If you have already followed that tutorial, you may encounter naming conflicts with existing resources (VMs, networks, storage volumes). Either clean up the existing resources first or modify the variable names in the Terraform configuration.
Requirements¶
Before using this Terraform configuration, ensure you have:
Terraform installed (version 1.0 or later)
LXD installed and initialized on your host machine (see the multi-member tutorial step 1)
Sufficient storage space as described in the multi-member tutorial (step 2)
Network connectivity for downloading Ubuntu images and snaps
Nested virtualization enabled as mentioned in the multi-member tutorial introduction
The host LXD should have:
A storage pool that meets the requirements described in the multi-member tutorial step 2
A bridge network for VM connectivity (configured during LXD initialization in the multi-member tutorial step 1)
Configuration overview¶
The Terraform configuration automates the entire MicroCloud setup process:
Infrastructure provisioning: Creates 4 Ubuntu VMs with proper resource allocation
Storage setup: Provisions local and Ceph storage disks for each VM
Network configuration: Sets up lookup and uplink network interfaces
Service installation: Installs MicroCloud, LXD, MicroCeph, and MicroOVN snaps via cloud-init
Cluster initialization: Uses preseed configuration to automatically initialize the MicroCloud cluster
The resulting setup matches the multi-member tutorial:
4 VMs:
micro1(initiator),micro2,micro3,micro4Storage: Local storage on all VMs, Ceph storage on first 3 VMs
Networking: OVN distributed networking with uplink connectivity
High availability: 3-node Ceph cluster for distributed storage
Setup steps¶
Navigate to the Terraform configuration:
cd demos/terraform/
Review and customize variables (optional): Edit
terraform.tfvarsto customize the VM names, IP addresses, and other variables.cp terraform.tfvars.example terraform.tfvars
Note
This Terraform configuration creates the same infrastructure as the manual multi-member tutorial. If you have already followed that tutorial, you may encounter naming conflicts with existing resources (VMs, networks, storage volumes). Either clean up the existing resources first or modify the variable names in the Terraform configuration.
Initialize Terraform:
terraform initReview the planned changes:
terraform planDeploy the infrastructure:
terraform applyVerify that the deployment is functioning: Check cluster status:
terraform output microcloud_status
Get the VMs IP addresses:
terraform output vm_ips
Confirm that you can access a cluster member:
lxc shell <cluster member name>
Configuration¶
To change these options, edit terraform.tfvars. The option values provided below are examples, and you must update them to suit your setup.
Change VMs names and IP addresses:
vm_names = ["node1", "node2", "node3", "node4"]
ip_base_offset = 50 # IPs will be .50, .60, .70, .80
Modify resource allocation:
cpu_per_instance = 4
memory_per_instance = 4 # GiB
Adjust storage configuration:
local_disk_size = "20GiB"
ceph_disk_size = "30GiB"
Use different snap channels:
microcloud_channel = "latest/edge"
lxd_channel = "latest/edge"
Network configuration¶
The configuration uses your existing LXD bridge network. To use a different network, modify the lookup_bridge option. Example:
lookup_bridge = "mybr0"
Cleanup¶
To remove the entire deployment, run:
terraform destroy
This will delete all VMs, storage volumes, and networks created by Terraform.