diff --git a/incus/modules/storage/main.tf b/incus/modules/storage/main.tf new file mode 100644 index 0000000..1192ec3 --- /dev/null +++ b/incus/modules/storage/main.tf @@ -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 +} diff --git a/incus/modules/storage/outputs.tf b/incus/modules/storage/outputs.tf new file mode 100644 index 0000000..52473fe --- /dev/null +++ b/incus/modules/storage/outputs.tf @@ -0,0 +1,7 @@ +output "name" { + value = incus_storage_pool.this.name +} + +output "driver" { + value = incus_storage_pool.this.driver +} diff --git a/incus/modules/storage/variables.tf b/incus/modules/storage/variables.tf new file mode 100644 index 0000000..f3bdbc0 --- /dev/null +++ b/incus/modules/storage/variables.tf @@ -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 = {} +} diff --git a/incus/storage.auto.tfvars b/incus/storage.auto.tfvars new file mode 100644 index 0000000..f0a9b82 --- /dev/null +++ b/incus/storage.auto.tfvars @@ -0,0 +1,7 @@ +incus_storage_pools = { + "san" = { + driver = "lvmcluster" + hypervisor_config = { "lvm.vg_name" = "nucVG" } + witness_config = { "lvm.vg_name" = "dummyVG" } + } +} diff --git a/incus/storage.tf b/incus/storage.tf new file mode 100644 index 0000000..e14b04e --- /dev/null +++ b/incus/storage.tf @@ -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 +} diff --git a/incus/variables.tf b/incus/variables.tf index cd26c19..6aa0517 100644 --- a/incus/variables.tf +++ b/incus/variables.tf @@ -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) + })) +}