resource "proxmox_virtual_environment_pool" "flock_pool" { comment = "Managed by Terraform" pool_id = var.flock_name } resource "proxmox_virtual_environment_vm" "wings" { count = length(var.wing_names) name = "${var.flock_name}-${var.wing_names[count.index]}" description = "Managed by Terraform" tags = ["terraform", "ubuntu", "wings", var.flock_name] node_name = "pve" vm_id = "${var.vm_id_prefix}${count.index + 101}" pool_id = proxmox_virtual_environment_pool.flock_pool.id cpu { cores = 4 type = "host" } memory { dedicated = 16384 floating = 16384 } agent { # read 'Qemu guest agent' section, change to true only when ready enabled = true } startup { order = "5" up_delay = "60" down_delay = "60" } disk { datastore_id = var.proxmox_vm_storage file_id = var.cloud_image_id interface = "virtio0" discard = "on" size = 16 file_format = "qcow2" } initialization { ip_config { ipv4 { # x.x.x.40 - x.x.x.55 address = "${cidrhost(var.subnet_cidr, count.index + 40)}/24" 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[0].user_data_file_id, # These will have manually provisioned disks disk, ] } } resource "ansible_host" "wings" { count = length(var.wing_names) name = "${proxmox_virtual_environment_vm.wings[count.index].name}.local" groups = ["${var.flock_name}_wings", var.flock_name] }