使用 terraform 将 ubuntu iso 部署到 proxmox

Deploy ubuntu iso into proxmox using terraform

我可以使用 cloud init(ubuntu 映像模板)在 Proxmox 中创建 VM。但是,现在我想在我有 iso 的地方创建 VM,但我无法创建 VM。我有一个包含 foo.iso, main.tf, vars.tf 的文件夹。我需要使用这个 foo.iso 在 proxmox 中创建虚拟机。有人可以帮我吗?任何线索将不胜感激。

这里是main.tf

terraform {
  required_providers {
    proxmox = {
      source = "telmate/proxmox"
      version = "2.9.1"
    }
  }
}

provider "proxmox" {
  
  pm_api_url = "https://foo:8006/api2/json"

  
  pm_api_token_id = ""

  pm_api_token_secret = "pass"

  
  pm_tls_insecure = true
}


resource "proxmox_vm_qemu" "test_server" {
  count = 1 # just want 1 for now, set to 0 and apply to destroy VM
  name = "test-vm-${count.index + 1}" #count.index starts at 0, so + 1 means this VM will be named test-vm-1 in proxmox

  
  target_node = var.proxmox_host

  # another variable with contents "ubuntu-2004-cloudinit-template"

 iso = "home/Terraform/foo.iso"

#clone is working fine but I need to the above one to work.
  clone = var.template_name

  # basic VM settings here. agent refers to guest agent
  agent = 1
  #os_type = "cloud-init"
  cores = 2
  sockets = 1
  cpu = "host"
  memory = 2048
  scsihw = "virtio-scsi-pci"
  bootdisk = "scsi0"

  disk {
    slot = 0
    size = "10G"
    type = "scsi"
    storage = "local-zfs"
    iothread = 1
  }
  
  network {
    model = "virtio"
    bridge = "vmbr0"
  }

  lifecycle {
    ignore_changes = [
      network,
    ]
  }
  
  
  # multiple VMs and have an IP assigned to each (.91, .92, .93, etc.)

  ipconfig0 = "ip=10.98.1.9${count.index + 1}/24,gw=10.98.1.1"
  
  # sshkeys set using variables. the variable contains the text of the key.
  sshkeys = <<EOF
  ${var.ssh_key}
  EOF
}

应用如下计划时出错。

Error: Cloud-init parameters only supported on clones or updates

  on main.tf line 20, in resource "proxmox_vm_qemu" "test_server":
   20: resource "proxmox_vm_qemu" "test_server" {

我认为您不能在使用 cloud-init 参数时设置 iso 变量:ipconfig0sshkeys

答案是去掉ip和ssh来创建vm。 试试这个,它应该有效

terraform {
  required_providers {
    proxmox = {
      source = "telmate/proxmox"
      version = "2.9.1"
    }
  }
}

provider "proxmox" {
  
  pm_api_url = "https://foo:8006/api2/json"

  
  pm_api_token_id = ""

  pm_api_token_secret = "pass"

  
  pm_tls_insecure = true
}


resource "proxmox_vm_qemu" "test_server" {
  count = 1 # just want 1 for now, set to 0 and apply to destroy VM
  name = "test-vm-${count.index + 1}" #count.index starts at 0, so + 1 means this VM will be named test-vm-1 in proxmox

  
  target_node = var.proxmox_host

  # another variable with contents "ubuntu-2004-cloudinit-template"

 iso = "home/Terraform/foo.iso"

#clone is working fine but I need to the above one to work.
  clone = var.template_name

  # basic VM settings here. agent refers to guest agent
  agent = 1
  #os_type = "cloud-init"
  cores = 2
  sockets = 1
  cpu = "host"
  memory = 2048
  scsihw = "virtio-scsi-pci"
  bootdisk = "scsi0"

  disk {
    slot = 0
    size = "10G"
    type = "scsi"
    storage = "local-zfs"
    iothread = 1
  }
  
  network {
    model = "virtio"
    bridge = "vmbr0"
  }

  lifecycle {
    ignore_changes = [
      network,
    ]
  }
  
 
}