Add reusable storage pool module with lvmcluster san pool

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-15 09:59:02 +01:00
parent 75273421fe
commit 6b53db3ad9
6 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
terraform {
required_providers {
incus = {
source = "lxc/incus"
}
}
}
resource "incus_storage_pool" "hypervisor" {
for_each = var.hypervisors
name = var.name
driver = var.driver
target = each.key
config = var.hypervisor_config
}
resource "incus_storage_pool" "witness" {
for_each = var.witnesses
name = var.name
driver = var.driver
target = each.key
config = var.witness_config
}
resource "incus_storage_pool" "this" {
depends_on = [
incus_storage_pool.hypervisor,
incus_storage_pool.witness,
]
name = var.name
driver = var.driver
}

View File

@@ -0,0 +1,7 @@
output "name" {
value = incus_storage_pool.this.name
}
output "driver" {
value = incus_storage_pool.this.driver
}

View File

@@ -0,0 +1,25 @@
variable "name" {
type = string
}
variable "driver" {
type = string
}
variable "hypervisors" {
type = set(string)
}
variable "witnesses" {
type = set(string)
}
variable "hypervisor_config" {
type = map(string)
default = {}
}
variable "witness_config" {
type = map(string)
default = {}
}

View File

@@ -0,0 +1,7 @@
incus_storage_pools = {
"san" = {
driver = "lvmcluster"
hypervisor_config = { "lvm.vg_name" = "nucVG" }
witness_config = { "lvm.vg_name" = "dummyVG" }
}
}

10
incus/storage.tf Normal file
View File

@@ -0,0 +1,10 @@
module "storage" {
source = "./modules/storage"
for_each = var.incus_storage_pools
name = each.key
driver = each.value.driver
hypervisors = toset(keys(var.incus_hypervisors))
witnesses = toset(keys(var.incus_witnesses))
hypervisor_config = each.value.hypervisor_config
witness_config = each.value.witness_config
}

View File

@@ -15,3 +15,11 @@ variable "incus_token" {
variable "incus_networks" {
type = map(number)
}
variable "incus_storage_pools" {
type = map(object({
driver = string
hypervisor_config = map(string)
witness_config = map(string)
}))
}