# # Source the Cloud Init Config file
# data "template_file" "cloud_init_fedora_vm_ipa" {
#   template  = "${file("${path.module}/files/cloud_init_fedora.cloud_config")}"
# 
#   vars = {
#     ssh_key = file("~/.ssh/id_ed25519.pub")
#     hostname = "ipa"
#     domain = var.domain
#   }
# }

## Create a local copy of the file, to transfer to Proxmox
#resource "local_file" "cloud_init_fedora_vm_ipa" {
#  #content   = data.template_file.cloud_init_fedora_vm_ipa.rendered
#  #content  = templatefile("${var.working_directory}/cloud-inits/cloud-init.cloud_config.tftpl", { ssh_key = var.public_ssh_key, hostname = "ipa" })
#  content  = templatefile("${path.module}/files/user_data_cloud_init_fedora_vm_ipa.cfg", { ssh_key = var.ssh_public_key, hostname = "ipa" , domain = var.domain})
#  filename  = "${path.module}/files/user_data_cloud_init_fedora_vm_ipa.cfg"
#}
#
## Transfer the file to the Proxmox Host
#resource "null_resource" "cloud_init_fedora_vm_ipa" {
#  connection {
#    type          = "ssh"
#    user          = "root"
#    private_key   = file("~/.ssh/id_ed25519")
#    host          = "pve.lab.softbox.net"
#  }
#
#  provisioner "file" {
#    source        = local_file.cloud_init_fedora_vm_ipa.filename
#    destination   = "/var/lib/vz/snippets/cloud_init_fedora_vm_ipa.yml"
#  }
#}
#
#
#/* Configure Cloud-Init User-Data with custom config file */
#resource "proxmox_vm_qemu" "cloudinit-fedora" {
#  depends_on = [
#    null_resource.cloud_init_fedora_vm_ipa,
#  ]
#
#  name        = "ipa"
#  #desc        = "FreeIPA Server"
#  target_node = "pve"
#
#  clone = "temp-fedora-38"
#
#  # The destination resource pool for the new VM
#  pool = "lab"
#
#  #storage = "local"
#  cpu {
#      cores = 2
#      sockets = 1
#      type = "host"
#  }
#
#  memory  = 2048
#  #disk_gb = 16
#  #nic     = "virtio"
#  #bridge  = "vmbr0"
#
#  ssh_user        = "root"
#  ssh_private_key = var.ssh_private_key
#  os_type   = "cloud-init"
#  ipconfig0 = "ip=10.11.12.65/24,gw=10.11.12.254"
#
#  /*
#    sshkeys and other User-Data parameters are specified with a custom config file.
#    In this example each VM has its own config file, previously generated and uploaded to
#    the snippets folder in the local storage in the Proxmox VE server.
#  */
#  cicustom                = "user=local:snippets/cloud_init_fedora_vm_ipa.yml"
#  /* Create the Cloud-Init drive on the "local-lvm" storage */
#  disks {
#    ide {
#      ide3 {
#        cloudinit {
#          storage = "local-lvm"
#        }
#      }
#    }
#  }
#  tags = "fedora"
#
#  #provisioner "remote-exec" {
#  #  inline = [
#  #    "ip a"
#  #  ]
#  #}
#}
#
#/* Uses custom eth1 user-net SSH portforward */
#resource "proxmox_vm_qemu" "vm_ipa" {
#  name        = "ipa"
#  #desc        = "FreeIPA Server"
#  target_node = "pve"
#
#  clone = "temp-fedora-38"
#  vmid = 111
#  agent = 1
#
#  # The destination resource pool for the new VM
#  pool = "lab"
#
#  cpu {
#      cores = 2
#      sockets = 1
#      type = "host"
#  }
#  tags = "ldap,samba,kerberos,dns,pki"
#
#  # Same CPU as the Physical host, possible to add cpu flags
#  # Ex: "host,flags=+md-clear;+pcid;+spec-ctrl;+ssbd;+pdpe1gb"
#  memory   = 2048
#  #scsihw   = "lsi"
#  scsihw   = "virtio-scsi-pci"
#  # Boot from hard disk (c), CD-ROM (d), network (n)
#  boot = "cdn"
#  # It's possible to add this type of material and use it directly
#  # Possible values are: network,disk,cpu,memory,usb
#  hotplug  = "network,disk,usb"
#  # Default boot disk
#  bootdisk = "virtio0"
#  # HA, you need to use a shared disk for this feature (ex: rbd)
#  hastate  = ""
#
#  #Display
#  vga {
#    type   = "serial0"
#    #Between 4 and 512, ignored if type is defined to serial
#    memory = 4
#  }
#
#  network {
#    id    = 0
#    model = "virtio"
#    bridge = "vmbr0"
#    macaddr   = "bc:24:11:de:2b:30"
#  }
#  disk {
#    #id           = 0
#    type         = "disk"
#    storage      = "local-lvm"
#    slot         = "virtio0"
#    #storage_type = "lvm"
#    size         = "16"
#    backup       = true
#  }
#  # Serial interface of type socket is used by xterm.js
#  # You will need to configure your guest system before being able to use it
#  serial {
#    id   = 0
#    type = "socket"
#  }
#  #preprovision    = true
#  ssh_forward_ip  = "10.11.12.1"
#  ssh_user        = "root"
#  ssh_private_key = var.ssh_private_key
#  os_type           = "ubuntu"
#  os_network_config = <<EOF
#auto eth0
#iface eth0 inet dhcp
#EOF
#
#  connection {
#    type        = "ssh"
#    user        = self.ssh_user
#    private_key = self.ssh_private_key
#    host        = self.ssh_host
#    port        = self.ssh_port
#  }
#
#  #provisioner "remote-exec" {
#  #  inline = [
#  #    "ip a"
#  #  ]
#  #}
#}
