Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions demos/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,17 @@ locals {

systems = [
for i, name in var.vm_names : {
name = name
ip = cidrhost(local.lookup_subnet, var.ip_base_offset + (i * var.ip_increment))
has_ceph = contains(var.ceph_nodes, name)
name = name
ip = cidrhost(local.lookup_subnet, var.ip_base_offset + (i * var.ip_increment))
has_ceph = contains(var.ceph_nodes, name)
disk_number = var.disk_number_start + i
}
Comment thread
mseralessandri marked this conversation as resolved.
]

ceph_disk_mapping = {
for i, system in local.systems : i => length([
for j, s in local.systems : j if j < i && s.has_ceph
]) if system.has_ceph
}
ceph_systems = [for s in local.systems : s if s.has_ceph]
}

resource "lxd_network" "microbr0" {
resource "lxd_network" "microbr" {
name = var.network_name

config = {
Expand All @@ -57,8 +54,8 @@ resource "lxd_network" "microbr0" {
}

resource "lxd_volume" "local_disk" {
count = var.vm_count
name = "${var.local_disk_name_prefix}${count.index + 1}"
count = length(local.systems)
name = "${var.local_disk_name_prefix}${local.systems[count.index].disk_number}"
pool = var.storage_pool
type = "custom"
content_type = "block"
Expand All @@ -68,8 +65,8 @@ resource "lxd_volume" "local_disk" {
}

resource "lxd_volume" "ceph_disk" {
count = length([for system in local.systems : system if system.has_ceph])
name = "${var.ceph_disk_name_prefix}${count.index + 1}"
count = length(local.ceph_systems)
name = "${var.ceph_disk_name_prefix}${local.ceph_systems[count.index].disk_number}"
pool = var.storage_pool
type = "custom"
Comment thread
mseralessandri marked this conversation as resolved.
content_type = "block"
Expand All @@ -79,7 +76,7 @@ resource "lxd_volume" "ceph_disk" {
}

resource "lxd_instance" "microcloud" {
count = var.vm_count
count = length(local.systems)
name = var.vm_names[count.index]
image = var.ubuntu_image
type = "virtual-machine"
Expand All @@ -90,7 +87,6 @@ resource "lxd_instance" "microcloud" {
}

config = {
"security.secureboot" = "false"
"cloud-init.user-data" = templatefile("${path.module}/cloud-init.yaml.tpl", {
hostname = var.vm_names[count.index]
lookup_interface = var.lookup_interface
Expand Down Expand Up @@ -123,7 +119,7 @@ resource "lxd_instance" "microcloud" {
type = "nic"
properties = {
nictype = "bridged"
parent = lxd_network.microbr0.name
parent = lxd_network.microbr.name
}
}

Expand All @@ -143,7 +139,7 @@ resource "lxd_instance" "microcloud" {
type = "disk"
properties = {
pool = var.storage_pool
source = lxd_volume.ceph_disk[local.ceph_disk_mapping[count.index]].name
source = lxd_volume.ceph_disk[index(local.ceph_systems[*].name, local.systems[count.index].name)].name
}
}
}
Expand Down Expand Up @@ -204,7 +200,7 @@ resource "lxd_instance" "microcloud" {

depends_on = [
data.lxd_network.lookup_bridge,
lxd_network.microbr0,
lxd_network.microbr,
lxd_volume.local_disk,
lxd_volume.ceph_disk
]
Expand Down
2 changes: 1 addition & 1 deletion demos/terraform/terraform.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ lookup_timeout = 300
instance_create_timeout = "25m"

# VM Configuration
vm_count = 4
vm_names = ["micro1", "micro2", "micro3", "micro4"]
ceph_nodes = ["micro1", "micro2", "micro3"]

Expand All @@ -46,6 +45,7 @@ ip_increment = 10
# Disk Name Configuration
local_disk_name_prefix = "local"
ceph_disk_name_prefix = "remote"
disk_number_start = 1

# MicroCloud Configuration
initiator = "micro1"
Expand Down
13 changes: 6 additions & 7 deletions demos/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,6 @@ variable "lookup_bridge" {
default = "lxdbr0"
}


variable "vm_count" {
description = "Number of VMs to create"
type = number
default = 4
}

variable "ip_base_offset" {
description = "Base IP address offset for the first VM"
type = number
Expand All @@ -179,6 +172,12 @@ variable "ceph_disk_name_prefix" {
default = "remote"
}

variable "disk_number_start" {
description = "Starting number for disk names (e.g., 1 for local1/remote1, 5 for local5/remote5)"
type = number
default = 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rather start at in index 0 by default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I started the index at 1 to match the tutorial naming (micro1) and to keep the disk names aligned as local1 and remote1.

}
Comment thread
mseralessandri marked this conversation as resolved.

variable "initiator" {
description = "Name of the initiator node for MicroCloud cluster (matches preseed initiator)"
type = string
Expand Down
Loading