terraform-provider-proxmox icon indicating copy to clipboard operation
terraform-provider-proxmox copied to clipboard

Machine value not saved in state after first tofu apply for proxmox_virtual_environment_vm resource when clonning

Open arsensimonyanpicsart opened this issue 1 year ago • 2 comments

Describe the bug When setting the machine value to “pc” in the resource configuration, the first tofu apply does not save the machine value in the state file. Running tofu plan after the first apply still shows changes to set the machine value. After the second tofu apply, the machine value is finally saved to the state.

To Reproduce

  1. Create a resource with the following configuration:
 terraform {
  required_providers {
    proxmox = {
      source  = "bpg/proxmox"
      version = "0.64.0"
    }
    time = {
      source = "hashicorp/time"
    }
  }
}

provider "proxmox" {
  endpoint  = "https://xxx:8006/"
  api_token = "xxx"
  insecure  = true
  ssh {
    agent    = true
    username = "xxx"
  }
}

provider "proxmox" {
  endpoint  = "https://xxx:8006/"
  api_token = "xxx"
  insecure  = true
  ssh {
    agent    = true
    username = "xxx"
    # password = "q]w[ep.69G]"
  }
}

 resource "proxmox_virtual_environment_vm" "vm" {
  name        = "xxx"
  description = "Managed by Terraform"
  pool_id     = "xxx"
  node_name   = "xxx"
  scsi_hardware = "virtio-scsi-single"
  acpi          = true
  bios          = "seabios"
  machine       = "pc"
  boot_order    = ["scsi0"]
  clone {
    vm_id     = 9000
    full      = true
    node_name = "xxx"
  }
  cpu {
    cores   = 1
    sockets = 1
    type    = "host"
  }
  memory {
    dedicated = 4096
  }
  network_device {
    bridge  = "vmbr0"
    vlan_id = 1045
    model   = "virtio"
  }
  disk {
    datastore_id = "Pure-NFS"
    interface    = "scsi0"
    size         = "10"
  }
  vga {
    type   = "std"
    memory = 16
  }
  tablet_device = true
  keyboard_layout = "en-us"
  operating_system {
    type = "l26"
  }
  agent {
    enabled = true
    timeout = "20s"
    trim    = false
    type    = "virtio"
  }
}
  1. Run tofu apply.

  2. Run tofu plan, observe that the machine value still shows as needing to be applied.

  3. Run tofu apply again.

  4. Observe that the machine type is now recorded in the state.

  5. Create a resource '....'

  6. Run '....'

  7. See error

  8. Modify the resource '....'

  9. Run '....'

  10. See error

Please also provide a minimal Terraform configuration that reproduces the issue.


terraform {
  required_providers {
    proxmox = {
      source  = "bpg/proxmox"
      version = "0.64.0"
    }
    time = {
      source = "hashicorp/time"
    }
  }
}

provider "proxmox" {
  endpoint  = "https://xxx:8006/"
  api_token = "xxx"
  insecure  = true
  ssh {
    agent    = true
    username = "xxx"
  }
}

resource "proxmox_virtual_environment_vm" "vm" {
  name        = "xxx"
  description = "Managed by Terraform"
  pool_id     = "xxx"
  node_name   = "xxx"
  scsi_hardware = "virtio-scsi-single"
  acpi          = true
  bios          = "seabios"
  machine       = "pc"
  boot_order    = ["scsi0"]
  clone {
    vm_id     = 9000
    full      = true
    node_name = "xxx"
  }
  cpu {
    cores   = 1
    sockets = 1
    type    = "host"
  }
  memory {
    dedicated = 4096
  }
  network_device {
    bridge  = "vmbr0"
    vlan_id = 1045
    model   = "virtio"
  }
  disk {
    datastore_id = "Pure-NFS"
    interface    = "scsi0"
    size         = "10"
  }
  vga {
    type   = "std"
    memory = 16
  }
  tablet_device = true
  keyboard_layout = "en-us"
  operating_system {
    type = "l26"
  }
  agent {
    enabled = true
    timeout = "20s"
    trim    = false
    type    = "virtio"
  }
}


and the output of terraform|tofu apply.


Expected behavior I expected the machine value to be saved in the state after the first tofu apply.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

  • Single or clustered Proxmox: Clustered
  • Proxmox version: 8.2.7
  • Provider version (ideally it should be the latest version): 0.64.0
  • Terraform/OpenTofu version: OpenTofu 1.8.3
  • OS (where you run Terraform/OpenTofu from): macos sonoma, ubuntu 22
  • Debug logs (TF_LOG=DEBUG terraform apply):

arsensimonyanpicsart avatar Oct 14 '24 18:10 arsensimonyanpicsart

Similar to #1575

bpg avatar Oct 15 '24 14:10 bpg

This can be a very frustrating issue when moving to production, as it might require rebooting all your provisioned vm_qemu hosts. We’ve already been impacted by this, with all MongoDB cluster nodes restarting together.

arsensimonyanpicsart avatar Nov 21 '24 11:11 arsensimonyanpicsart