mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-15 12:42:24 -04:00
terraform: QEMU node groups (#1961)
* init add variables add amount to instance_group again fix tf validate rollback old names make fields optional fix image ref mini daniel comments use latest * Update cli/internal/terraform/terraform/qemu/main.tf Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com> * add uid to resource name * make machine a global variable again * fix tf --------- Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com>
This commit is contained in:
parent
161bb37cba
commit
9bb91ca447
11 changed files with 202 additions and 188 deletions
|
@ -28,25 +28,26 @@ provider "registry.terraform.io/dmacvicar/libvirt" {
|
|||
}
|
||||
|
||||
provider "registry.terraform.io/hashicorp/random" {
|
||||
version = "3.4.3"
|
||||
version = "3.5.1"
|
||||
constraints = "3.5.1"
|
||||
hashes = [
|
||||
"h1:hV66lcagXXRwwCW3Y542bI1JgPo8z/taYKT7K+a2Z5U=",
|
||||
"h1:hXUPrH8igYBhatzatkp80RCeeUJGu9lQFDyKemOlsTo=",
|
||||
"h1:saZR+mhthL0OZl4SyHXZraxyaBNVMxiZzks78nWcZ2o=",
|
||||
"h1:tL3katm68lX+4lAncjQA9AXL4GR/VM+RPwqYf4D2X8Q=",
|
||||
"h1:xZGZf18JjMS06pFa4NErzANI98qi59SEcBsOcS2P2yQ=",
|
||||
"zh:41c53ba47085d8261590990f8633c8906696fa0a3c4b384ff6a7ecbf84339752",
|
||||
"zh:59d98081c4475f2ad77d881c4412c5129c56214892f490adf11c7e7a5a47de9b",
|
||||
"zh:686ad1ee40b812b9e016317e7f34c0d63ef837e084dea4a1f578f64a6314ad53",
|
||||
"h1:3hjTP5tQBspPcFAJlfafnWrNrKnr7J4Cp0qB9jbqf30=",
|
||||
"h1:6FVyQ/aG6tawPam6B+oFjgdidKd83uG9n7dOSQ66HBA=",
|
||||
"h1:IL9mSatmwov+e0+++YX2V6uel+dV6bn+fC/cnGDK3Ck=",
|
||||
"h1:VSnd9ZIPyfKHOObuQCaKfnjIHRtR7qTw19Rz8tJxm+k=",
|
||||
"h1:sZ7MTSD4FLekNN2wSNFGpM+5slfvpm5A/NLVZiB7CO0=",
|
||||
"zh:04e3fbd610cb52c1017d282531364b9c53ef72b6bc533acb2a90671957324a64",
|
||||
"zh:119197103301ebaf7efb91df8f0b6e0dd31e6ff943d231af35ee1831c599188d",
|
||||
"zh:4d2b219d09abf3b1bb4df93d399ed156cadd61f44ad3baf5cf2954df2fba0831",
|
||||
"zh:6130bdde527587bbe2dcaa7150363e96dbc5250ea20154176d82bc69df5d4ce3",
|
||||
"zh:6cc326cd4000f724d3086ee05587e7710f032f94fc9af35e96a386a1c6f2214f",
|
||||
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
|
||||
"zh:84103eae7251384c0d995f5a257c72b0096605048f757b749b7b62107a5dccb3",
|
||||
"zh:8ee974b110adb78c7cd18aae82b2729e5124d8f115d484215fd5199451053de5",
|
||||
"zh:9dd4561e3c847e45de603f17fa0c01ae14cae8c4b7b4e6423c9ef3904b308dda",
|
||||
"zh:bb07bb3c2c0296beba0beec629ebc6474c70732387477a65966483b5efabdbc6",
|
||||
"zh:e891339e96c9e5a888727b45b2e1bb3fcbdfe0fd7c5b4396e4695459b38c8cb1",
|
||||
"zh:ea4739860c24dfeaac6c100b2a2e357106a89d18751f7693f3c31ecf6a996f8d",
|
||||
"zh:f0c76ac303fd0ab59146c39bc121c5d7d86f878e9a69294e29444d4c653786f8",
|
||||
"zh:f143a9a5af42b38fed328a161279906759ff39ac428ebcfe55606e05e1518b93",
|
||||
"zh:b6d88e1d28cf2dfa24e9fdcc3efc77adcdc1c3c3b5c7ce503a423efbdd6de57b",
|
||||
"zh:ba74c592622ecbcef9dc2a4d81ed321c4e44cddf7da799faa324da9bf52a22b2",
|
||||
"zh:c7c5cde98fe4ef1143bd1b3ec5dc04baf0d4cc3ca2c5c7d40d17c0e9b2076865",
|
||||
"zh:dac4bad52c940cd0dfc27893507c1e92393846b024c5a9db159a93c534a3da03",
|
||||
"zh:de8febe2a2acd9ac454b844a4106ed295ae9520ef54dc8ed2faf29f12716b602",
|
||||
"zh:eab0d0495e7e711cca367f7d4df6e322e6c562fc52151ec931176115b83ed014",
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -50,47 +50,27 @@ resource "docker_container" "qemu_metadata" {
|
|||
}
|
||||
|
||||
|
||||
|
||||
module "control_plane" {
|
||||
module "node_group" {
|
||||
source = "./modules/instance_group"
|
||||
role = "control-plane"
|
||||
amount = var.control_plane_count
|
||||
vcpus = var.vcpus
|
||||
memory = var.memory
|
||||
state_disk_size = var.state_disk_size
|
||||
cidr = "10.42.1.0/24"
|
||||
base_name = var.name
|
||||
for_each = var.node_groups
|
||||
node_group_name = each.key
|
||||
role = each.value.role
|
||||
amount = each.value.instance_count
|
||||
state_disk_size = each.value.disk_size
|
||||
vcpus = each.value.vcpus
|
||||
memory = each.value.memory
|
||||
machine = var.machine
|
||||
cidr = each.value.role == "control-plane" ? "10.42.1.0/24" : "10.42.2.0/24"
|
||||
network_id = libvirt_network.constellation.id
|
||||
pool = libvirt_pool.cluster.name
|
||||
boot_mode = var.constellation_boot_mode
|
||||
boot_volume_id = libvirt_volume.constellation_os_image.id
|
||||
kernel_volume_id = local.kernel_volume_id
|
||||
initrd_volume_id = local.initrd_volume_id
|
||||
kernel_cmdline = local.kernel_cmdline
|
||||
machine = var.machine
|
||||
kernel_cmdline = each.value.role == "control-plane" ? local.kernel_cmdline : var.constellation_cmdline
|
||||
firmware = var.firmware
|
||||
nvram = var.nvram
|
||||
name = var.name
|
||||
}
|
||||
|
||||
module "worker" {
|
||||
source = "./modules/instance_group"
|
||||
role = "worker"
|
||||
amount = var.worker_count
|
||||
vcpus = var.vcpus
|
||||
memory = var.memory
|
||||
state_disk_size = var.state_disk_size
|
||||
cidr = "10.42.2.0/24"
|
||||
network_id = libvirt_network.constellation.id
|
||||
pool = libvirt_pool.cluster.name
|
||||
boot_mode = var.constellation_boot_mode
|
||||
boot_volume_id = libvirt_volume.constellation_os_image.id
|
||||
kernel_volume_id = local.kernel_volume_id
|
||||
initrd_volume_id = local.initrd_volume_id
|
||||
kernel_cmdline = var.constellation_cmdline
|
||||
machine = var.machine
|
||||
firmware = var.firmware
|
||||
nvram = var.nvram
|
||||
name = var.name
|
||||
}
|
||||
|
||||
resource "libvirt_pool" "cluster" {
|
||||
|
|
|
@ -4,12 +4,15 @@ terraform {
|
|||
source = "dmacvicar/libvirt"
|
||||
version = "0.7.1"
|
||||
}
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = "3.5.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "libvirt_domain" "instance_group" {
|
||||
name = "${var.name}-${var.role}-${count.index}"
|
||||
count = var.amount
|
||||
name = "${var.base_name}-${var.role}-${local.group_uid}-${count.index}"
|
||||
memory = var.memory
|
||||
vcpu = var.vcpus
|
||||
machine = var.machine
|
||||
|
@ -56,21 +59,36 @@ resource "libvirt_domain" "instance_group" {
|
|||
}
|
||||
|
||||
resource "libvirt_volume" "boot_volume" {
|
||||
name = "constellation-${var.role}-${count.index}-boot"
|
||||
count = var.amount
|
||||
name = "constellation-${var.role}-${local.group_uid}-${count.index}-boot"
|
||||
pool = var.pool
|
||||
base_volume_id = var.boot_volume_id
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
name, # required. Allow legacy scale sets to keep their old names
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "state_volume" {
|
||||
name = "constellation-${var.role}-${count.index}-state"
|
||||
count = var.amount
|
||||
name = "constellation-${var.role}-${local.group_uid}-${count.index}-state"
|
||||
pool = var.pool
|
||||
size = local.state_disk_size_byte
|
||||
format = "qcow2"
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
name, # required. Allow legacy scale sets to keep their old names
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "random_id" "uid" {
|
||||
byte_length = 4
|
||||
}
|
||||
|
||||
locals {
|
||||
group_uid = random_id.uid.hex
|
||||
state_disk_size_byte = 1073741824 * var.state_disk_size
|
||||
ip_range_start = 100
|
||||
kernel = var.boot_mode == "direct-linux-boot" ? var.kernel_volume_id : null
|
||||
|
|
|
@ -84,8 +84,12 @@ variable "nvram" {
|
|||
type = string
|
||||
description = "path to UEFI NVRAM template file. Used for secure boot."
|
||||
}
|
||||
|
||||
variable "name" {
|
||||
variable "base_name" {
|
||||
type = string
|
||||
description = "name prefix of the cluster VMs"
|
||||
}
|
||||
|
||||
variable "node_group_name" {
|
||||
type = string
|
||||
description = "name of the node group"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
output "ip" {
|
||||
value = module.control_plane.instance_ips[0]
|
||||
value = module.node_group["control_plane_default"].instance_ips[0]
|
||||
}
|
||||
|
||||
output "uid" {
|
||||
|
|
|
@ -1,3 +1,25 @@
|
|||
variable "node_groups" {
|
||||
type = map(object({
|
||||
role = string
|
||||
instance_count = number // number of instances in the node group
|
||||
disk_size = number // size of state disk (GiB)
|
||||
vcpus = number
|
||||
memory = number // amount of memory per instance (MiB)
|
||||
}))
|
||||
validation {
|
||||
condition = can([for group in var.node_groups : group.role == "control-plane" || group.role == "worker"])
|
||||
error_message = "The role has to be 'control-plane' or 'worker'."
|
||||
}
|
||||
|
||||
description = "A map of node group names to node group configurations."
|
||||
}
|
||||
|
||||
variable "machine" {
|
||||
type = string
|
||||
default = "q35"
|
||||
description = "machine type. use 'q35' for secure boot and 'pc' for non secure boot. See 'qemu-system-x86_64 -machine help'"
|
||||
}
|
||||
|
||||
variable "libvirt_uri" {
|
||||
type = string
|
||||
description = "libvirt socket uri"
|
||||
|
@ -43,38 +65,6 @@ variable "image_format" {
|
|||
default = "qcow2"
|
||||
description = "image format"
|
||||
}
|
||||
|
||||
variable "control_plane_count" {
|
||||
type = number
|
||||
description = "amount of control plane nodes"
|
||||
}
|
||||
|
||||
variable "worker_count" {
|
||||
type = number
|
||||
description = "amount of worker nodes"
|
||||
}
|
||||
|
||||
variable "vcpus" {
|
||||
type = number
|
||||
description = "amount of vcpus per instance"
|
||||
}
|
||||
|
||||
variable "memory" {
|
||||
type = number
|
||||
description = "amount of memory per instance (MiB)"
|
||||
}
|
||||
|
||||
variable "state_disk_size" {
|
||||
type = number
|
||||
description = "size of state disk (GiB)"
|
||||
}
|
||||
|
||||
variable "machine" {
|
||||
type = string
|
||||
default = "q35"
|
||||
description = "machine type. use 'q35' for secure boot and 'pc' for non secure boot. See 'qemu-system-x86_64 -machine help'"
|
||||
}
|
||||
|
||||
variable "firmware" {
|
||||
type = string
|
||||
default = "/usr/share/OVMF/OVMF_CODE.secboot.fd"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue