Files
terraform-modules/lawndale-vm/compute.tf
Tamas Kiss e6ae06dbbe
Some checks failed
continuous-integration/drone/push Build is failing
fix: lawndale-vm module ref
2022-05-26 23:35:21 +02:00

119 lines
2.5 KiB
HCL

resource "libvirt_pool" "this" {
count = var.create_root_storage_pool ? 1 : 0
name = local.root_storage_pool
type = "dir"
path = "/vmstore/${var.name}"
}
resource "libvirt_volume" "this" {
name = local.root_storage_volume_name
pool = local.root_storage_pool
size = var.root_storage_volume_size_gb * 1024 * 1024 * 1024
base_volume_name = var.base_image_volume
base_volume_pool = var.base_image_pool
}
resource "macaddress" "this" {
}
module "ipam" {
source = "git@git.thomasklein.me:thomasklein/terraform-modules//lawndale-vm-ipam"
id = var.id
name = var.name
interface = var.interface
}
resource "libvirt_domain" "this" {
name = "${var.id}-${var.name}"
description = var.description
vcpu = var.vcpu
memory = var.memory_mb
autostart = var.autostart
cloudinit = libvirt_cloudinit_disk.this.id
network_interface {
bridge = module.ipam.lawndale_interface
mac = macaddress.this.address
}
disk {
volume_id = libvirt_volume.this.id
scsi = true
}
# video { type = "virtio" }
# graphics {}
console {
type = "pty"
target_port = 0
target_type = "serial"
}
qemu_agent = true
dynamic "filesystem" {
for_each = var.filesystems
content {
source = filesystem.value.source
target = filesystem.value.target
readonly = filesystem.value.readonly
accessmode = filesystem.value.accessmode
}
}
dynamic "xml" {
for_each = var.xslt == null ? [] : [var.xslt]
content {
xslt = xml.value
}
}
}
resource "libvirt_cloudinit_disk" "this" {
name = "${var.id}-${var.name}-cloudinit"
pool = local.root_storage_pool
meta_data = local.meta_data
network_config = local.network_config
user_data = var.user_data
}
locals {
default_network_config = {
version = 2
ethernets = {
eth = {
match = {
macaddress = macaddress.this.address
}
addresses = [
"${module.ipam.ip_address}/${module.ipam.cidr}"
]
gateway4 = module.ipam.gateway
nameservers = {
search = module.ipam.search_domains
addresses = [
module.ipam.nameserver
]
}
}
}
}
default_meta_data = <<EOM
instance-id: ${var.id}-${var.name}
local-hostname: ${var.name}
EOM
meta_data = var.meta_data != null ? var.meta_data : local.default_meta_data
network_config = var.network_config != null ? var.network_config : jsonencode(local.default_network_config)
}