demos/terraform: Improve MicroCloud resource naming#1428
Draft
mseralessandri wants to merge 5 commits into
Draft
demos/terraform: Improve MicroCloud resource naming#1428mseralessandri wants to merge 5 commits into
mseralessandri wants to merge 5 commits into
Conversation
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>
roosterfish
requested changes
Jun 26, 2026
| variable "disk_number_start" { | ||
| description = "Starting number for disk names (e.g., 1 for local1/remote1, 5 for local5/remote5)" | ||
| type = number | ||
| default = 1 |
Contributor
There was a problem hiding this comment.
Should we rather start at in index 0 by default?
There was a problem hiding this comment.
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_startto support offset-based disk numbering. - Refactored locals/resources to carry
disk_numberthrough to LXD volume names and storage-related outputs. - Renamed the
lxd_networkTerraform resource label to avoid hardcodingmicrobr0.
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 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 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR avoids hardcoding the bridge variable name to
microbr0, so deployments can use different network names such asmicrobr1when 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