iac/terraform/mcaptcha/mcaptcha.tf

56 lines
1.4 KiB
HCL

# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
resource "libvirt_volume" "mcaptcha_volume" {
name = "mcaptcha_volume-${count.index}"
base_volume_id = libvirt_volume.debian-mcaptcha-qcow2.id
count = var.mcaptcha_vm_count
pool = libvirt_pool.mcaptcha_basic.name
size = var.mcaptcha_vm_disk_size
}
resource "libvirt_domain" "mcaptcha_mcaptcha" {
count = var.mcaptcha_vm_count
name = "mcaptcha_mcaptcha_${count.index}"
memory = var.mcaptcha_vm_memory
vcpu = var.mcaptcha_vm_vcpu
qemu_agent = true
cloudinit = libvirt_cloudinit_disk.commoninit.id
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
network_interface {
macvtap = var.macvtap_ethernet_interface
wait_for_lease = true
}
disk {
volume_id = element(libvirt_volume.mcaptcha_volume.*.id, count.index)
}
}
locals {
mcaptcha_vm_ips = [for i in libvirt_domain.mcaptcha_mcaptcha : i.network_interface.0.addresses[0]]
mcaptcha_vm_names = [for i in libvirt_domain.mcaptcha_mcaptcha : i.name]
mcaptcha_vm_map = [for i in libvirt_domain.mcaptcha_mcaptcha : {
ip = i.network_interface.0.addresses[0],
name = i.name
}]
}