2023-03-11 16:10:21 +00:00
|
|
|
terraform {
|
|
|
|
backend "pg" {
|
|
|
|
schema_name = "dmz_dns"
|
|
|
|
}
|
|
|
|
|
|
|
|
required_providers {
|
|
|
|
libvirt = {
|
|
|
|
source = "dmacvicar/libvirt"
|
|
|
|
}
|
|
|
|
template = {
|
|
|
|
source = "hashicorp/template"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
provider "libvirt" {
|
|
|
|
uri = var.libvirt_endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "libvirt_volume" "main_disk" {
|
|
|
|
name = "${var.name}.iso"
|
|
|
|
pool = "disk"
|
|
|
|
size = 1024 * 1024 * 1024 * 15
|
|
|
|
base_volume_name = "debian-bookworm.qcow2"
|
|
|
|
base_volume_pool = "iso"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "libvirt_cloudinit_disk" "cloudinit" {
|
|
|
|
name = "${var.name}.iso"
|
|
|
|
pool = "init"
|
|
|
|
user_data = templatefile("cloud_init.cfg.tftpl", { name = var.name, host_public_key = var.host_public_key })
|
2023-03-16 22:13:37 +00:00
|
|
|
network_config = templatefile("network_config.cfg.tftpl", { internal_ip = var.internal_ip })
|
2023-03-11 16:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "libvirt_domain" "ubuntu" {
|
2023-03-16 22:13:37 +00:00
|
|
|
name = "hermes"
|
2023-03-11 16:10:21 +00:00
|
|
|
memory = 1024
|
|
|
|
vcpu = 4
|
|
|
|
|
|
|
|
disk {
|
|
|
|
volume_id = libvirt_volume.main_disk.id
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
2023-03-16 22:13:37 +00:00
|
|
|
bridge = "dmzbr"
|
2023-03-16 22:29:28 +00:00
|
|
|
hostname = var.name
|
|
|
|
mac = "CA:FE:C0:FF:EE:07"
|
2023-03-11 16:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cloudinit = libvirt_cloudinit_disk.cloudinit.id
|
2023-03-11 17:04:58 +00:00
|
|
|
|
2023-03-13 20:52:35 +00:00
|
|
|
provisioner "local-exec" {
|
2023-03-17 08:27:52 +00:00
|
|
|
command = "ansible-playbook -e internal_ip=${var.internal_ip} -T 60 -u root -i ${var.ansible_inventory} ${var.ansible_playbook}"
|
2023-03-16 22:13:37 +00:00
|
|
|
|
|
|
|
environment = {
|
|
|
|
ANSIBLE_HOST_KEY_CHECKING = "False"
|
2023-03-17 16:26:03 +00:00
|
|
|
ANSIBLE_CONFIG = "${var.ansible_cfg}"
|
2023-03-16 22:13:37 +00:00
|
|
|
}
|
2023-03-13 20:52:35 +00:00
|
|
|
}
|
2023-03-16 22:29:28 +00:00
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
replace_triggered_by = [
|
|
|
|
libvirt_cloudinit_disk.cloudinit.id
|
|
|
|
]
|
|
|
|
}
|
2023-03-11 16:10:21 +00:00
|
|
|
}
|