Home > Blockchain >  Deploy ubuntu iso into proxmox using terraform
Deploy ubuntu iso into proxmox using terraform

Time:12-01

I can able to create VM using cloud init (ubuntu image template) into Proxmox. But, now I want to create VM where I have iso and I was not able to create VM. I have a folder which contains foo.iso, main.tf, vars.tf. I need to use this foo.iso to create VM inside proxmox. Can anybody help me with this? Any leads will be appreciated.

Here is 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 while applying the plan as below.

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" {

CodePudding user response:

The answer is to remove ip and ssh to create vm. Try this, It should work

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,
    ]
  }
  
 
}

CodePudding user response:

I don't think you can have the iso variable set while using the cloud-init parameters: ipconfig0 and sshkeys.

  • Related