diff --git a/infra/main.tofu b/infra/main.tofu index 315ce3f..eb45ebf 100644 --- a/infra/main.tofu +++ b/infra/main.tofu @@ -32,35 +32,9 @@ resource "incus_image" "this" { } } -resource "incus_profile" "this" { - name = "Default" - description = "The default profile applied to both masters and workers." - project = incus_project.this.name - - depends_on = [incus_network.this] - - config = { - "limits.cpu" = var.cpus - "limits.memory" = var.memory - "boot.autostart" = false - "security.secureboot" = false - } - - device { - name = "root" - type = "disk" - - properties = { - "pool" = "default" - "path" = "/" - "size" = local.root_disk_size - } - } -} - resource "incus_network" "this" { - name = "deskpi-cluster" - description = "An emulated network for the DeskPi Super6C cluster project." + name = "home-infrastructure" + description = "An emulated home infrastructure stack." project = incus_project.this.name type = "bridge" @@ -77,19 +51,23 @@ module "master" { name = "master-${count.index}" project = incus_project.this.name image = incus_image.this.fingerprint - profiles = [incus_profile.this.name] + cpu = 2 + memory = "2GiB" + network = incus_network.this.name ipv4_address = cidrhost(local.network_cidr, 2 + (2 * count.index)) } module "worker" { source = "./modules/incus_vm" - count = local.master_count + count = local.worker_count name = "worker-${count.index}" project = incus_project.this.name image = incus_image.this.fingerprint - profiles = [incus_profile.this.name] + cpu = 2 + memory = "2GiB" + network = incus_network.this.name ipv4_address = cidrhost(local.network_cidr, 3 + (2 * count.index)) } diff --git a/infra/modules/incus_vm/main.tofu b/infra/modules/incus_vm/main.tofu index 42e5d89..5149c1f 100644 --- a/infra/modules/incus_vm/main.tofu +++ b/infra/modules/incus_vm/main.tofu @@ -14,7 +14,7 @@ resource "incus_instance" "this" { type = "virtual-machine" image = var.image - profiles = var.profiles + profiles = concat([incus_profile.this.name], var.profiles) wait_for { type = "agent" @@ -53,3 +53,27 @@ resource "incus_storage_volume" "this" { "size" = "16GiB" } } + +resource "incus_profile" "this" { + name = var.name + description = "Default profile for ${var.name}" + project = var.project + + config = { + "limits.cpu" = var.cpu + "limits.memory" = var.memory + "boot.autostart" = false + "security.secureboot" = true + } + + device { + name = "root" + type = "disk" + + properties = { + "pool" = "default" + "path" = "/" + "size" = "16GiB" + } + } +} diff --git a/infra/modules/incus_vm/variables.tofu b/infra/modules/incus_vm/variables.tofu index 29177f5..7c7375c 100644 --- a/infra/modules/incus_vm/variables.tofu +++ b/infra/modules/incus_vm/variables.tofu @@ -27,6 +27,7 @@ variable "profiles" { type = list(string) description = "The profiles for this instance." nullable = false + default = [] } variable "network" { @@ -40,3 +41,15 @@ variable "ipv4_address" { description = "The IPv4 address for this instance." nullable = false } + +variable "cpu" { + type = number + description = "The number of CPUs for this instance." + nullable = false +} + +variable "memory" { + type = string + description = "The amount of memory allocated for this instance." + nullable = false +}