94 lines
1.8 KiB
HCL

locals {
dns_server = {
name = "dns-server"
}
}
resource "proxmox_virtual_environment_vm" "dns_server" {
name = local.dns_server.name
description = "Managed by Terraform"
tags = ["terraform", "ubuntu", "dns-server"]
node_name = "pve"
vm_id = var.vm_id
pool_id = var.pool_id
cpu {
cores = 2
type = "host"
}
memory {
dedicated = 1024
floating = 1024
}
agent {
# read 'Qemu guest agent' section, change to true only when ready
enabled = true
}
# This should be one of the first nodes to start up to provide DNS globally
startup {
order = "0"
up_delay = "60"
down_delay = "60"
}
disk {
datastore_id = var.proxmox_vm_storage
file_id = var.cloud_image_id
interface = "virtio0"
iothread = true
discard = "on"
size = 16
file_format = "qcow2"
}
initialization {
ip_config {
ipv4 {
address = var.ipv4_address
gateway = var.gateway
}
}
datastore_id = var.proxmox_image_storage
user_data_file_id = var.cloud_init_file_id
}
network_device {
bridge = "vmbr0"
}
operating_system {
type = "l26"
}
connection {
type = "ssh"
user = "ubuntu"
private_key = file(var.ssh_private_key_file)
host = split("/", self.initialization[0].ip_config[0].ipv4[0].address)[0]
}
provisioner "remote-exec" {
inline = [
"sudo hostnamectl set-hostname ${self.name}",
"sudo systemctl restart avahi-daemon",
]
}
lifecycle {
ignore_changes = [
initialization,
]
}
}
resource "ansible_host" "dns_server" {
# Use mDNS rather than IP
name = "${local.dns_server.name}.local"
groups = ["core", "dns_server"]
}