Skip to content

demos/terraform: Improve MicroCloud resource naming#1428

Draft
mseralessandri wants to merge 5 commits into
canonical:mainfrom
mseralessandri:microcloud_resource_naming
Draft

demos/terraform: Improve MicroCloud resource naming#1428
mseralessandri wants to merge 5 commits into
canonical:mainfrom
mseralessandri:microcloud_resource_naming

Conversation

@mseralessandri

Copy link
Copy Markdown
Contributor

This PR avoids hardcoding the bridge variable name to microbr0, so deployments can use different network names such as microbr1 when needed.
It also supports custom VM numbering (for example micro5, micro6, micro7, micro8) with matching disk naming (i.e. local7, remote7...), making the demo reusable in environments where lower indexes are already occupied for multiple MicroCloud deployments on the same host.

Checklist

Signed-off-by: Maria Seralessandri <maria.seralessandri@canonical.com>
Signed-off-by: Maria Seralessandri <maria.seralessandri@canonical.com>
Signed-off-by: Maria Seralessandri <maria.seralessandri@canonical.com>
Signed-off-by: Maria Seralessandri <maria.seralessandri@canonical.com>
Signed-off-by: Maria Seralessandri <maria.seralessandri@canonical.com>
@mseralessandri mseralessandri changed the title Improved MicroCloud resource naming demos/terraform: Improve MicroCloud resource naming Jun 25, 2026
@roosterfish roosterfish requested a review from Copilot June 26, 2026 07:20
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?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Terraform demo to make network and disk resource naming more configurable, aiming to support non-default bridge names and custom starting indices for VM/disk numbering so the demo can be reused across multiple deployments on the same host.

Changes:

  • Added disk_number_start to support offset-based disk numbering.
  • Refactored locals/resources to carry disk_number through to LXD volume names and storage-related outputs.
  • Renamed the lxd_network Terraform resource label to avoid hardcoding microbr0.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
demos/terraform/variables.tf Adds disk_number_start (recommended to validate as a positive integer).
demos/terraform/terraform.tfvars.example Documents the new disk_number_start variable in example inputs.
demos/terraform/outputs.tf Updates storage_layout output to include disk numbers in by-id paths (currently inconsistent with preseed inputs).
demos/terraform/main.tf Adds per-system disk_number, updates LXD resource naming, and refactors Ceph disk selection logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +182 to +186
variable "disk_number_start" {
description = "Starting number for disk names (e.g., 1 for local1/remote1, 5 for local5/remote5)"
type = number
default = 1
}
Comment on lines 42 to 45
for i, system in local.systems : system.name => {
local_disk = "${var.disk_device_base}${var.local_disk_name_prefix}"
ceph_disk = system.has_ceph ? "${var.disk_device_base}${var.ceph_disk_name_prefix}" : null
local_disk = "${var.disk_device_base}${var.local_disk_name_prefix}${system.disk_number}"
ceph_disk = system.has_ceph ? "${var.disk_device_base}${var.ceph_disk_name_prefix}${system.disk_number}" : null
}
Comment thread demos/terraform/main.tf
Comment on lines +35 to 39
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 demos/terraform/main.tf
Comment on lines 67 to 71
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants