feat: modularise incus vm
This commit is contained in:
+22
-87
@@ -7,8 +7,8 @@ locals {
|
|||||||
ext_disk_size = "16GiB"
|
ext_disk_size = "16GiB"
|
||||||
network_cidr = "10.150.0.1/24"
|
network_cidr = "10.150.0.1/24"
|
||||||
|
|
||||||
master_count = 1
|
master_count = 2
|
||||||
worker_count = 1
|
worker_count = 0
|
||||||
|
|
||||||
image = "ubuntu/26.04"
|
image = "ubuntu/26.04"
|
||||||
}
|
}
|
||||||
@@ -70,93 +70,28 @@ resource "incus_network" "this" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "incus_instance" "master" {
|
module "master" {
|
||||||
count = local.master_count
|
source = "./modules/incus_vm"
|
||||||
|
count = local.master_count
|
||||||
|
|
||||||
name = "master-${count.index}"
|
name = "master-${count.index}"
|
||||||
description = "Kubernetes Master ${count.index}"
|
project = incus_project.this.name
|
||||||
project = incus_project.this.name
|
image = incus_image.this.fingerprint
|
||||||
|
profiles = [incus_profile.this.name]
|
||||||
type = "virtual-machine"
|
network = incus_network.this.name
|
||||||
image = incus_image.this.fingerprint
|
ipv4_address = cidrhost(local.network_cidr, 2 + (2 * count.index))
|
||||||
profiles = [incus_profile.this.name]
|
|
||||||
|
|
||||||
wait_for {
|
|
||||||
type = "agent"
|
|
||||||
}
|
|
||||||
|
|
||||||
device {
|
|
||||||
name = "eth0"
|
|
||||||
type = "nic"
|
|
||||||
|
|
||||||
properties = {
|
|
||||||
"network" = incus_network.this.name
|
|
||||||
"ipv4.address" = cidrhost(local.network_cidr, 2 + (2 * count.index))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
device {
|
|
||||||
name = "ext"
|
|
||||||
type = "disk"
|
|
||||||
|
|
||||||
properties = {
|
|
||||||
"pool" = "default"
|
|
||||||
"source" = incus_storage_volume.master[count.index].name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "incus_storage_volume" "master" {
|
module "worker" {
|
||||||
count = local.master_count
|
source = "./modules/incus_vm"
|
||||||
|
count = local.master_count
|
||||||
|
|
||||||
name = "master-ext-${count.index}"
|
name = "worker-${count.index}"
|
||||||
description = "External drive for master ${count.index}"
|
project = incus_project.this.name
|
||||||
pool = "default"
|
image = incus_image.this.fingerprint
|
||||||
project = incus_project.this.name
|
profiles = [incus_profile.this.name]
|
||||||
|
network = incus_network.this.name
|
||||||
content_type = "block"
|
ipv4_address = cidrhost(local.network_cidr, 3 + (2 * count.index))
|
||||||
|
|
||||||
config = {
|
|
||||||
"size" = local.ext_disk_size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "incus_instance" "worker" {
|
|
||||||
count = local.worker_count
|
|
||||||
|
|
||||||
name = "worker-${count.index}"
|
|
||||||
description = "Kubernetes Worker ${count.index}"
|
|
||||||
project = incus_project.this.name
|
|
||||||
|
|
||||||
type = "virtual-machine"
|
|
||||||
image = incus_image.this.fingerprint
|
|
||||||
profiles = [incus_profile.this.name]
|
|
||||||
|
|
||||||
wait_for {
|
|
||||||
type = "agent"
|
|
||||||
}
|
|
||||||
|
|
||||||
device {
|
|
||||||
name = "eth0"
|
|
||||||
type = "nic"
|
|
||||||
|
|
||||||
properties = {
|
|
||||||
"network" = incus_network.this.name
|
|
||||||
"ipv4.address" = cidrhost(local.network_cidr, 3 + (2 * count.index))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# -------
|
|
||||||
# Outputs
|
|
||||||
# -------
|
|
||||||
|
|
||||||
output "master_addresses" {
|
|
||||||
value = incus_instance.master[*].ipv4_address
|
|
||||||
}
|
|
||||||
|
|
||||||
output "worker_addresses" {
|
|
||||||
value = incus_instance.worker[*].ipv4_address
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---------
|
# ---------
|
||||||
@@ -164,12 +99,12 @@ output "worker_addresses" {
|
|||||||
# ---------
|
# ---------
|
||||||
|
|
||||||
terraform {
|
terraform {
|
||||||
required_version = "~> 1"
|
required_version = "~> 1.12"
|
||||||
|
|
||||||
required_providers {
|
required_providers {
|
||||||
incus = {
|
incus = {
|
||||||
source = "lxc/incus"
|
source = "lxc/incus"
|
||||||
version = "~> 1"
|
version = "~> 1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
incus = {
|
||||||
|
source = "lxc/incus"
|
||||||
|
version = ">= 1.1.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "incus_instance" "this" {
|
||||||
|
name = var.name
|
||||||
|
description = var.description
|
||||||
|
project = var.project
|
||||||
|
|
||||||
|
type = "virtual-machine"
|
||||||
|
image = var.image
|
||||||
|
profiles = var.profiles
|
||||||
|
|
||||||
|
wait_for {
|
||||||
|
type = "agent"
|
||||||
|
}
|
||||||
|
|
||||||
|
device {
|
||||||
|
name = "eth0"
|
||||||
|
type = "nic"
|
||||||
|
|
||||||
|
properties = {
|
||||||
|
"network" = var.network
|
||||||
|
"ipv4.address" = var.ipv4_address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
device {
|
||||||
|
name = "ext"
|
||||||
|
type = "disk"
|
||||||
|
|
||||||
|
properties = {
|
||||||
|
"pool" = "default"
|
||||||
|
"source" = incus_storage_volume.this.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "incus_storage_volume" "this" {
|
||||||
|
name = "${var.name}-ext"
|
||||||
|
description = "External disk for ${var.name}"
|
||||||
|
pool = "default"
|
||||||
|
project = var.project
|
||||||
|
|
||||||
|
content_type = "block"
|
||||||
|
|
||||||
|
config = {
|
||||||
|
"size" = "16GiB"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
variable "name" {
|
||||||
|
type = string
|
||||||
|
description = "The name for this instance."
|
||||||
|
nullable = false
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "description" {
|
||||||
|
type = string
|
||||||
|
description = "The description for this instance."
|
||||||
|
nullable = false
|
||||||
|
default = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "project" {
|
||||||
|
type = string
|
||||||
|
description = "The project this instance belongs to."
|
||||||
|
nullable = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "image" {
|
||||||
|
type = string
|
||||||
|
description = "The image for this instance."
|
||||||
|
nullable = false
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "profiles" {
|
||||||
|
type = list(string)
|
||||||
|
description = "The profiles for this instance."
|
||||||
|
nullable = false
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "network" {
|
||||||
|
type = string
|
||||||
|
description = "The network for this instance."
|
||||||
|
nullable = false
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ipv4_address" {
|
||||||
|
type = string
|
||||||
|
description = "The IPv4 address for this instance."
|
||||||
|
nullable = false
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user