Telmate / terraform-provider-proxmox

Terraform provider plugin for proxmox
MIT License
2.12k stars 512 forks source link

The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. #388

Closed radosevic closed 1 year ago

radosevic commented 3 years ago

Greetings, I am bumping my head for days... Am I doing something wrong? Every version ( tried 2.6.5, 2.6.6, 2.6.7, 2.7.1, 2.7.2, 2.7.3 and 2.7.4 ) of telmate/proxmox provider I tried gives me this panic/error:

panic: interface conversion: interface {} is nil, not string

Version of Proxmox:

root@some-proxmox:~# pveversion 
pve-manager/6.3-6/2184247e (running kernel: 4.19.0-16-amd64)

VM template is Ubuntu cloud image prepared by recommendations from Proxmox wiki + added qemu agent. I get new cloned image, but provider breaks when starts doing disk block, so at the end disk is not resized and doesn't push cloud-init settings.

This is last entry in Proxmox-provider.log:

{"data":{"type":"dir","active":1,"total":391120543744,"avail":359123881984,"content":"iso,rootdir,vztmpl,images,snippets","used":24010919936,"shared":0,"enabled":1}}
unusedDiskNames: []
Fri, 20 Aug 2021 18:21:37 +0200 DBG github.com/Telmate/terraform-provider-proxmox/proxmox/resource_vm_qemu.go:843 > Original disks: 'map[0:map[backup:1 cache:none discard:on file: format:qcow2 iothread:1 mbps:0 mbps_rd:0 mbps_rd_max:0 mbps_wr:0 mbps_wr_max:0 media:disk replicate:1 size:50G slot:0 ssd:0 storage:local storage_type: type:scsi volume:]]', Clone Disks 'map[0:map[file:1001/vm-1001-disk-0.qcow2 format:qcow2 size:2252M slot:0 storage:local storage_type:dir type:scsi volume:local:1001/vm-1001-disk-0.qcow2]]' loggerName=resource_vm_create vmid=

I can provide you with Terraform debug/trace logs if needed.

It is always breaking when doing disk block:

goroutine 97 [running]:
github.com/Telmate/proxmox-api-go/proxmox.(*Client).createVMDisks(0xc000364280, 0xc00011e6f0, 0x14, 0xc00033a7d8, 0x1d, 0x0, 0x0, 0xc000038d94, 0x7)
        github.com/Telmate/proxmox-api-go@v0.0.0-20210713150936-9bfd169c655f/proxmox/client.go:834 +0x772
github.com/Telmate/proxmox-api-go/proxmox.ConfigQemu.UpdateConfig(0x0, 0xc00011e690, 0x12, 0xc000180540, 0x1d, 0x0, 0x0, 0xc000038d94, 0x7, 0x1, ...)
        github.com/Telmate/proxmox-api-go@v0.0.0-20210713150936-9bfd169c655f/proxmox/config_qemu.go:312 +0xac9
github.com/Telmate/terraform-provider-proxmox/proxmox.resourceVmQemuCreate(0xc000092f80, 0x1777c20, 0xc0003647d0, 0x0, 0x0)
        github.com/Telmate/terraform-provider-proxmox/proxmox/resource_vm_qemu.go:861 +0x2bdb
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0000e8460, 0x19a1978, 0xc0000c13c0, 0xc000092f80, 0x1777c20, 0xc0003647d0, 0x0, 0x0, 0x0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.6.1/helper/schema/resource.go:318 +0x1ee
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0000e8460, 0x19a1978, 0xc0000c13c0, 0xc0001c0380, 0xc0004b7bc0, 0x1777c20, 0xc0003647d0, 0x0, 0x0, 0x0, ...)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.6.1/helper/schema/resource.go:456 +0x67b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00000c090, 0x19a1978, 0xc0000c13c0, 0xc0007c47d0, 0xc0000c13c0, 0x1871da0, 0xc00035e600)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.6.1/helper/schema/grpc_provider.go:955 +0x8ef
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0xc00064ebc0, 0x19a1a20, 0xc0000c13c0, 0xc0001c00e0, 0xc00064ebc0, 0xc00035e660, 0xc00032bba0)
        github.com/hashicorp/terraform-plugin-go@v0.3.0/tfprotov5/server/server.go:332 +0xb5
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x1871da0, 0xc00064ebc0, 0x19a1a20, 0xc00035e660, 0xc00058ca80, 0x0, 0x19a1a20, 0xc00035e660, 0xc000248000, 0xfec)
        github.com/hashicorp/terraform-plugin-go@v0.3.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000274c40, 0x19a9258, 0xc000319c80, 0xc0001a8000, 0xc0002d6660, 0x1db8d60, 0x0, 0x0, 0x0)
        google.golang.org/grpc@v1.32.0/server.go:1194 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc000274c40, 0x19a9258, 0xc000319c80, 0xc0001a8000, 0x0)
        google.golang.org/grpc@v1.32.0/server.go:1517 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc00030a190, 0xc000274c40, 0x19a9258, 0xc000319c80, 0xc0001a8000)
        google.golang.org/grpc@v1.32.0/server.go:859 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.32.0/server.go:857 +0x1fd

Error: The terraform-provider-proxmox_v2.7.4 plugin crashed!

my main.tf file:

resource "proxmox_vm_qemu" "vm" {
  count = var.create_vm ? var.number_of_vms : 0

  name        = "${var.name}${count.index+1}"
  target_node = var.target_node
  vmid        = var.vmid
  desc        = var.desc
  bios        = var.bios
  onboot      = var.onboot
  boot        = var.boot
  bootdisk    = var.bootdisk
  agent       = var.agent
  clone       = var.clone
  full_clone  = var.full_clone
  qemu_os     = var.qemu_os
  memory      = var.memory
  balloon     = var.balloon
  cores       = var.cores
  sockets     = var.sockets
  vcpus       = var.vcpus
  cpu         = var.cpu
  numa        = var.numa
  kvm         = var.kvm
  hotplug     = var.hotplug
  scsihw      = var.scsihw

  dynamic "vga" {
    for_each = var.vga
    content {
      type   = vga.value.type
      memory = vga.value.memory
    }
  }

  dynamic "disk" {
    for_each = var.disk
    content {
      type        = disk.value.type
      storage     = disk.value.storage
      size        = disk.value.size
      format      = disk.value.format
      cache       = disk.value.cache
      backup      = disk.value.backup
      iothread    = disk.value.iothread
      replicate   = disk.value.replicate
      ssd         = disk.value.ssd
      discard     = disk.value.discard
      mbps        = disk.value.mbps
      mbps_rd     = disk.value.mbps_rd
      mbps_rd_max = disk.value.mbps_rd_max
      mbps_wr     = disk.value.mbps_wr
      mbps_wr_max = disk.value.mbps_wr_max
      file        = disk.value.file
      media       = disk.value.media
      volume      = disk.value.volume
      slot        = disk.value.slot
    }
  }

  dynamic "network" {
    for_each = var.network
    content {
      model     = network.value.model
      macaddr   = network.value.macaddr
      bridge    = network.value.bridge
      tag       = network.value.tag
      firewall  = network.value.firewall
      rate      = network.value.rate
      queues    = network.value.queues
      link_down = network.value.link_down
    }
  }

  dynamic "serial" {
    for_each = var.serial
    content {
      id   = var.serial.id
      type = var.serial.type
    }
  }

  lifecycle {
    ignore_changes = [
      network,
    ]
  }

  # Cloud Init Settings
  #ipconfig0 = "ip=192.168.100.1${count.index + 1}/24,gw=192.168.100.1"
  ipconfig0 = "ip=${var.ipv4}/${var.cidr},gw=${var.gw}"
  sshkeys = <<EOF
  ${var.sshkeys}
  EOF

  connection {
    user     = var.ssh_user
    host     = var.ssh_host
    private_key = "${file(var.ssh_private_key)}"
  }

  provisioner "remote-exec" {
    inline = [
      "/sbin/ip a"
    ]
  }
}

#data "local_file" "public_key" {
#  filename = "${path.root}~/.ssh/id_rsa.pub"
#}

variables.tf:

variable "number_of_vms" {
  description = "Number of VMs to deploy"
  type        = number
  default     = 1
}

#########################################################################################
# Arguments are supported in the Terraform Telmate Proxmox 
# ** Provider Block **
#########################################################################################

variable "api_url" {
  description = "This is the target Proxmox API endpoint. REQUIRED(or use environment variable PM_API_URL)"
  type        = string
  default     = "https://proxmox.example.com:8006/api2/json"
}

variable "user" {
  description = "The Proxmox User. REQUIRED(or use environment variable PM_USER)"
  type        = string
  default     = "terraform@pam"
}

variable "password" {
  description = "The Proxmox User Password. REQUIRED(or use environment variable PM_PASS)"
  type        = string
  default     = null
}

variable "otp" {
  description = "The 2FA OTP code. (or use environment variable PM_OTP)"
  type        = string
  default     = null
}

variable "tls_insecure" {
  description = "Disable TLS verification while connecting. Default: false"
  type        = string
  default     = true
}

variable "parallel" {
  description = "Allowed simultaneous Proxmox processes(e.g. creating resources). Default: 4"
  type        = number
  default     = null
}

variable "log_enable" {
  description = "Enable debug logging, see the section below for logging details. Default: false"
  type        = string
  default     = true
}

variable "log_levels" {
  description = "A map of log sources and levels"
  type = map(object({
    _default    = string
    _capturelog = string
  }))
  default = {
  }
}

variable "log_file" {
  description = "If logging is enabled, the log file the provider will write logs to. Default: terraform-plugin-proxmox.log"
  type        = string
  default     = "terraform-proxmox.log"
}

variable "timeout" {
  description = "Timeout value (seconds) for proxmox API calls. Default: 300"
  type        = number
  default     = 600
}

#########################################################################################
# Arguments are supported in the Terraform Telmate Proxmox 
# ** Resource Block **
#########################################################################################

variable "create_vm" {
  description = "Check for VM Creation"
  type        = bool
  default     = true
}

variable "name" {
  description = "Name of the VM. REQUIRED"
  type        = string
  default     = null
}

variable "target_node" {
  description = "Target Proxmox-VE Node to place the VM on. REQUIRED"
  type        = string
  default     = null
}

variable "vmid" {
  description = "The (unique) ID of the VM in Proxmox. Default: next number in the sequence"
  type        = number
  default     = 1000
}

variable "desc" {
  description = "Description for the VM. Only used on the configuration web interface. This is saved as comment inside the configuration file"
  type        = string
  default     = null
}

variable "bios" {
  description = "Select BIOS implementation(ovmf | seabios). Default: seabios"
  type        = string
  default     = "seabios"
}

variable "onboot" {
  description = "Specifies whether a VM will be started during system bootup. Default: true"
  type        = bool
  default     = true
}

variable "boot" {
  description = "Boot on floppy (a), hard disk (c), CD-ROM (d), or network (n). Default: cdn"
  type        = string
  default     = "cdn"
}

variable "bootdisk" {
  description = "Enable booting from specified disk(ide|sata|scsi|virtio)\\d+. Sample: scsi0 or virtio0"
  type        = string
  default     = "scsi0"
}

variable "agent" {
  description = "Enables QEMU Agent option for this VM.  When 1, then qemu-guest-agent must be installed on the guest. Default: 0"
  type        = number
  default     = 1
}

variable "iso" {
  description = "ISO file uploaded on the Proxmox-VE storage. Set only ISO or CLONE. Sample: local:iso/proxmox-mailgateway_2.1.iso"
  type        = string
  default     = null
}

variable "clone" {
  description = "The name of the Proxmox-VE Template. It will be used to provision a new VM by Terraform"
  type        = string
  default     = null
}

variable "full_clone" {
  description = "Whether to run a full or linked clone from the template. Default: true"
  type        = bool
  default     = true
}

variable "hastate" {
  description = "HA, you need to use a shared disk for this feature (ex: rbd)"
  type        = string
  default     = null
}

variable "qemu_os" {
  description = "Specify guest operating system. This is used to enable special optimization/features for specific operating systems. Default: l26"
  type        = string
  default     = "l26"
}

variable "memory" {
  description = "Amount of RAM for the VM in MB. This is the maximum available memory when you use the balloon device. Default: 512"
  type        = number
  default     = 512
}

variable "balloon" {
  description = "Amount of target RAM for the VM in MB. Using 0 disables the ballon driver. Default: 0"
  type        = number
  default     = 1
}

variable "cores" {
  description = "The number of CPU cores per socket to give the VM. Default: 1"
  type        = number
  default     = 1
}

variable "sockets" {
  description = "The number of CPU sockets. Default: 1"
  type        = number
  default     = 1
}

variable "vcpus" {
  description = "Number of hotplugged vCPUs. Default: 0"
  type        = number
  default     = 1
}

variable "cpu" {
  description = "Emulated CPU type. For best performance(homogeneous cluster where all nodes have the same CPU), set this to host. Default: host"
  type        = string
  default     = "host"
}

variable "numa" {
  description = "Enable/disable NUMA. Default: false"
  type        = bool
  default     = true
}

variable "kvm" {
  description = "Enable/disable KVM hardware virtualization. Default: true"
  type        = bool
  default     = true
}

variable "hotplug" {
  description = "Selectively enable hotplug features. This is a comma separated list of hotplug features: network, disk, cpu, memory and usb. Default: network,disk,usb"
  type        = string
  default     = "disk,network,usb,cpu,memory "
}

variable "scsihw" {
  description = "SCSI controller model. (lsi | lsi53c810 | megasas | pvscsi | virtio-scsi-pci | virtio-scsi-single)"
  type        = string
  default     = "virtio-scsi-single"
}

/*
 ** memory :                - Sets the VGA memory (in MiB). Has no effect with serial display. (4 - 512)
 ** type   : Default: "std" - Set the VGA type (cirrus | none | qxl | qxl2 | qxl3 | qxl4 | serial0 | serial1 | serial2 | serial3 | std | virtio | vmware)
*/
variable "vga" {
  description = "Configure the VGA Hardware. Default(for type): std"
  type = list(object({
    type   = string
    memory = number
  }))
  default = [
    {
      type   = "serial0"
      memory = null
    }
  ]
}

/*
  ** model     : REQUIRED       - Network Card Model. The virtio model provides the best performance with very low CPU overhead
                                  If your guest does not support this driver, it is usually best to use e1000
                                  (e1000 | e1000-82540em | e1000-82544gc | e1000-82545em | i82551 | i82557b | i82559er | ne2k_isa | ne2k_pci | pcnet | rtl8139 | virtio | vmxnet3)
  ** macaddr   :                - A common MAC address with the I/G (Individual/Group) bit not set
  ** bridge    : Default: "nat" - However; The Proxmox VE standard bridge is called vmbr0. Bridge to attach the network device to
  ** tag       : Default: -1    - VLAN tag to apply to packets on this interface. (1 - 4094)
  ** firewall  : Default: false - Whether this interface should be protected by the firewall
  ** rate      :                - Rate limit in mbps (megabytes per second) as floating point number. (0 - N)
  ** queues    :                - Number of packet queues to be used on the device. (0 - 16)
  ** link_down :                - Whether this interface should be disconnected (like pulling the plug)
*/
variable "network" {
  description = "Specify network devices"
  type = list(object({
    model     = string
    macaddr   = string
    bridge    = string
    tag       = number
    firewall  = bool
    rate      = number
    queues    = number
    link_down = bool
  }))
  default = [
    {
      model     = "virtio"
      macaddr   = null
      bridge    = "vmbr0"
      tag       = null
      firewall  = false
      rate      = null
      queues    = null
      link_down = false
    }
  ]
}

/*
  ** type        : REQUIRED        - Disk Type - (ide|sata|scsi|virtio)
  ** storage     : REQUIRED        - Target storage
  ** size        : REQUIRED        - Disk size. This is purely informational and has no effect
  ** format      :                 - Set the drive’s backing file’s data format (cloop | cow | qcow | qcow2 | qed | raw | vmdk)
  ** cache       : Default: "none" - Set the drive’s cache mode (directsync | none | unsafe | writeback | writethrough)
  ** backup      : Default: false  - Whether the drive should be included when making backups
  ** iothread    : Default: false  - Whether to use iothreads for this drive
  ** replicate   : Default: false  - Whether the drive should considered for replication jobs
  ** ssd         :                 - Whether to expose this drive as an SSD, rather than a rotational hard disk
  ** discard     :                 - Controls whether to pass discard/trim requests to the underlying storage
  ** mbps        : Default: 0      - Maximum r/w speed in megabytes per second
  ** mbps_rd     : Default: 0      - Maximum read speed in megabytes per second
  ** mbps_rd_max : Default: 0      - Maximum unthrottled read pool in megabytes per second
  ** mbps_wr     : Default: 0      - Maximum write speed in megabytes per second
  ** mbps_wr_max : Default: 0      - Maximum unthrottled write pool in megabytes per second
  ** file        :                 - The drive’s backing volume
  ** media       :                 - Set the drive’s media type (cdrom | disk)
  ** volume      :                 -
  ** slot        :                 -
*/
variable "disk" {
  description = "Specify disk variables"
  type = list(object({
    type        = string
    storage     = string
    size        = string
    format      = string
    cache       = string
    backup      = number
    iothread    = number
    replicate   = number
    ssd         = number
    discard     = string
    mbps        = number
    mbps_rd     = number
    mbps_rd_max = number
    mbps_wr     = number
    mbps_wr_max = number
    file        = string
    media       = string
    volume      = string
    slot        = number
  }))
  default = [
    {
      type        = "scsi"
      storage     = "local"
      size        = "32G"
      format      = "raw"
      cache       = "none"
      backup      = 1
      iothread    = 1
      replicate   = 1
      ssd         = null
      discard     = "on"
      mbps        = null
      mbps_rd     = null
      mbps_rd_max = null
      mbps_wr     = null
      mbps_wr_max = null
      file        = null
      media       = "disk"
      volume      = null
      slot        = null
    }
    ]
}

/*
 ** id     : REQUIRED - ID is 0 to 3
 ** type   : REQUIRED - socket
*/
variable "serial" {
  description = "Create a serial device inside the VM. Serial interface of type socket is used by xterm.js. Using a serial device as terminal"
  type = object({
    id   = number
    type = string
  })
  default = {
    id   = 0
    type = "socket"
  }
}

variable "pool" {
  description = "The destination resource pool for the new VM"
  type        = string
  default     = null
}

variable "force_create" {
  description = "Default: false"
  type        = string
  default     = false
}

variable "clone_wait" {
  description = "Giving time(second) to Proxmox-VE to catchup. Default: 15"
  type        = number
  default     = null
}

#########################################################################################
# ** The following arguments are specifically for Linux for preprovisioning **
# ** It phase which is used to set a hostname, intialize eth0, and resize the VM disk **
# ** REQUIRES define_connection_info to be TRUE **
#########################################################################################
variable "define_connection_info" {
  description = "Define the (SSH) connection parameters for preprovisioners. It allow user to opt-out of setting the connection info for the resource. Default: true"
  type        = bool
  default     = true
}

variable "preprovision" {
  description = "Enable/Disabled Pre-Provisioning. For more detail Telmate vm_qemu.md. Default: true"
  type        = bool
  default     = true
}

variable "os_type" {
  description = "Which provisioning method to use, based on the OS type. Possible values: ubuntu, centos, cloud-init. For more detail Telmate vm_qemu.md"
  type        = string
  default     = "cloud-init"
}

variable "os_network_config" {
  description = "Linux provisioning specific, /etc/network/interfaces for Ubuntu and /etc/sysconfig/network-scripts/ifcfg-eth0 for CentOS"
  type        = string
  default     = null
}

variable "ssh_forward_ip" {
  description = "Address used to connect to the VM"
  type        = string
  default     = null
}

variable "ssh_host" {
  description = "Hostname or IP Address used to connect to the VM"
  type        = string
  default     = null
}

variable "ssh_port" {
  description = "SSH port used to connect to the VM"
  type        = string
  default     = null
}

variable "ssh_user" {
  description = "Username to login in the VM when preprovisioning"
  type        = string
  default     = null
}

variable "ssh_private_key" {
  description = "Private key to login in the VM when preprovisioning"
  type        = string
  default     = null
}

#########################################################################################
# Arguments are supported in the Terraform Telmate Proxmox 
# ** Resource Block Cloud Init Specific Variables **
# ** Also the following arguments are specifically for Cloud-init for preprovisioning **
#########################################################################################

variable "ci_wait" {
  description = "Cloud-init specific, how to long to wait for preprovisioning. Default: 30"
  type        = number
  default     = null
}

variable "ciuser" {
  description = "Cloud-init specific, Overwrite image Default User"
  type        = string
  default     = null
}

variable "cipassword" {
  description = "Cloud-init specific, Password to assign the user. Using this is generally not recommended. Use ssh keys instead"
  type        = string
  default     = null
}

variable "cicustom" {
  description = "Cloud-init specific, location of the custom cloud-config files"
  type        = string
  default     = null
}

variable "searchdomain" {
  description = "Cloud-init specific, sets DNS search domains for a container"
  type        = string
  default     = null
}

variable "nameserver" {
  description = "Cloud-init specific, sets DNS server IP address for a container"
  type        = string
  default     = null
}

variable "sshkeys" {
  description = "Setup public SSH keys (one key per line, OpenSSH format)"
  type        = string
  default     = null
}

variable "ipconfig0" {
  description = "Cloud-init specific, Specify IP addresses and gateways for the corresponding interface. [gw=] [,gw6=] [,ip=<IPv4Format/CIDR>] [,ip6=<IPv6Format/CIDR>]"
  type        = string
  default     = null
}

variable "ipconfig1" {
  description = "Cloud-init specific, Specify IP addresses and gateways for the corresponding interface. [gw=] [,gw6=] [,ip=<IPv4Format/CIDR>] [,ip6=<IPv6Format/CIDR>]"
  type        = string
  default     = null
}

variable "ipconfig2" {
  description = "Cloud-init specific, Specify IP addresses and gateways for the corresponding interface. [gw=] [,gw6=] [,ip=<IPv4Format/CIDR>] [,ip6=<IPv6Format/CIDR>]"
  type        = string
  default     = null
}

variable "force_recreate_on_change_of" {
  description = "Allows this to depend on another resource, that when changed, needs to re-create this vm. An example where this is useful is a cloudinit configuration (as the cicustom attribute points to a file not the content)"
  type        = string
  default     = null
}

#########################################################################################
# IP address settings
# GW address
# CIDR / subnet
#########################################################################################

variable "ipv4" {
  description = "IP address to use on interface."
  type        = string
  default     = null
}

variable "cidr" {
  description = "CIDR / subnet"
  type        = number
  default     = 24
}

variable "gw" {
  description = "Gateway IP address to use on interface."
  type        = string
  default     = null
}

terraform.tfvars:

# Number of VMs to deploy
number_of_vms = 1
agent = 1

# VM configuration
name        = "ubuntu-testclone-"
target_node = "some-node"
vmid        = "1001"
desc        = "Test VM deployed by Terraform"
#bios        = var.bios
#onboot      = var.onboot
#boot        = var.boot
#bootdisk    = var.bootdisk
#agent       = var.agent
clone       = "ubuntu-20.04-template-latest"
#full_clone  = var.full_clone
#qemu_os     = var.qemu_os
memory      = "4096"
#balloon     = var.balloon
cores       = "8"
#sockets     = var.sockets
#vcpus       = var.vcpus
#cpu         = var.cpu
#numa        = var.numa
#kvm         = var.kvm
#hotplug     = var.hotplug
#scsihw      = var.scsihw

# Proxmox API credentials
api_url = "https://some-host:8006/api2/json"
user = "root@pam"
password = "some_password"
#tls_insecure = var.tls_insecure

# Main disk configuration
disk = [
    {
      type        = "scsi"
      storage     = "local"
      size        = "50G"
      format      = "qcow2"
      cache       = "none"
      backup      = 1
      #backup      = true
      iothread    = 1
      #iothread    = true
      replicate   = 1
      #replicate   = true
      ssd         = 0
      #ssd         = true
      discard     = "on"
      mbps        = null
      mbps_rd     = null
      mbps_rd_max = null
      mbps_wr     = null
      mbps_wr_max = null
      file        = null
      media       = "disk"
      volume      = null
      slot        = null
    }
  ]

# Network configuration
network = [
    {
      model     = "virtio"
      macaddr   = null
      bridge    = "vmbr0"
      tag       = null
      firewall  = false
      rate      = null
      queues    = null
      link_down = false
    }
  ]

# IP configuration
ipv4 = "192.168.100.12"
#cidr = var.cidr
gw = "192.168.100.1"

# SSH configuration for preprovisioning
ssh_user = "some_user"
ssh_private_key = "~/.ssh/id_rsa"
sshkeys = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDTVTrsh8nM8eE0RgsUD6XlHKZjsLfBozwZVdOIODOqYV7cAmDrtyMtglHlVYYU0pTXeVFjbabow8SyNgCiGHgGeJaiK3zBM6ssI060NIUNDGUTuitwft0QAClLn5DpY5CaeMvRMyMVJFLZomRyVOgf1ROzmM7vQLHpetI36aOGMNedFUvMTPutfg+IcUm/5Xvkea3+clthv7Xdt2BpoxD3JXFn9pCpjVEU+L2099AAcyHCbeM53iQqb0Qic4h0W4JwOsP4dTrbaDSTvlcrUGtwNwqAX3395VjZI9I+IRtIpM/H81tEO5Xs0nya8FXEcLiSfCejaCob4Toew6L1apQT4q+tZYIQXU6nVfBNIW7hFWi8cNcqwFaOlZ0j1oLuhxGCqWFaDA6TZ3bdQLwxUev/Vl2aLKkxBYnXcVY6qk/WWV4uZKZGIBXTIhDapEbQXYFs+lQlcSDfa6qWC4WBuWC34nf2irRARXYn9GKw/iMd7wMWVROXf2A6M/bV+GN4U8kFUYi9O/oJZ9lAw12hiF8rhmUmmegyjnvkB637ZLgL1QjQByf1fKR2VfeGgGTOOZywCYSkS1nw6hFiykI+oxWf90BGSwtyNQ1/DUs6UzqZcD0Px01pHEHHYZ2CCOqpRCLev2zwvIeKHSPN7AuLVDqIkE14RjmPrHoTd4RNMy4W9Q=="

versions.tf:

terraform {
  required_version = ">= 0.15.0"
  required_providers {
    proxmox = {
      source = "Telmate/proxmox"
      version = "2.7.4"
    }
  }
}

provider.tf:

provider "proxmox" {
  pm_api_url      = var.api_url
  pm_user         = var.user
  pm_password     = var.password
  #pm_otp         = var.otp
  pm_tls_insecure = var.tls_insecure
  #pm_parallel    = var.parallel
  pm_log_enable   = var.log_enable
  #pm_log_levels   = var.log_levels
  pm_log_file     = var.log_file
  pm_timeout      = var.timeout
}
emil-jacero commented 3 years ago

Hi, have you had any success in figuring out what the cause is?

h-phil commented 3 years ago

I had exactly the same error and it seems that there are multiple issues that can cause this output.
Anyone with the same issue, I would suggest you to activate debug logging like this and check the log output:

provider "proxmox" {
    ...
    pm_log_enable = true
    pm_log_file = "terraform-plugin-proxmox.log"
    pm_log_levels = {
      _default = "debug"
      _capturelog = ""
    }
}

In my case it was not really a config Issue!
Somehow passing the secrets as ENV variables was not working as described and I had to pass it in the provider with pm_api_token_id/pm_api_token_secret.

h-phil commented 3 years ago

@radosevic I had a quick look at your config and if you remove media from your disk it seems to work. main.tf:

  dynamic "disk" {
    for_each = var.disk
    content {
      type        = disk.value.type
      storage     = disk.value.storage
      size        = disk.value.size
      format      = disk.value.format
      cache       = disk.value.cache
      backup      = disk.value.backup
      iothread    = disk.value.iothread
      replicate   = disk.value.replicate
      ssd         = disk.value.ssd
      discard     = disk.value.discard
      mbps        = disk.value.mbps
      mbps_rd     = disk.value.mbps_rd
      mbps_rd_max = disk.value.mbps_rd_max
      mbps_wr     = disk.value.mbps_wr
      mbps_wr_max = disk.value.mbps_wr_max
      file        = disk.value.file
      #media       = disk.value.media
      volume      = disk.value.volume
      slot        = disk.value.slot
    }
  }

Not sure why though. (maybe somewhere here: https://github.com/Telmate/proxmox-api-go/blob/5e4c0d698a7828f63fab0656aaa31dbe310a6912/proxmox/client.go#L842 )

gverbist commented 2 years ago

same issue on proxmox 7

ApolloDS commented 2 years ago

I was following the description here: https://austinsnerdythings.com/2021/09/01/how-to-deploy-vms-in-proxmox-with-terraform/ and had the same error. I did a debug logging but could not see any error in it (API communication ok).

ApolloDS commented 2 years ago

Problem solved, see here: https://github.com/Telmate/terraform-provider-proxmox/issues/414

"I had the same problem. I connect to a proxmox in my local network using a self-signed certificate, so I had to add the provider setting pm_tls_insecure = true"

weetabix commented 2 years ago

Problem solved, see here: #414

"I had the same problem. I connect to a proxmox in my local network using a self-signed certificate, so I had to add the provider setting pm_tls_insecure = true"

I have had that setting since day one in my test environment, and have only now run into the GRPC provider bug. This is not a solution.

shyce commented 2 years ago

Same problem here. My machine stack comes up 1 out of 3 times if I'm lucky.

SkYNewZ commented 2 years ago

Same issue too with basic resource :

resource "proxmox_vm_qemu" "worker" {
  count = var.number_of_masters

  target_node = "galaxy"
  name        = "worker0${count.index + 1}"
  vmid        = count.index + 111

  full_clone = true
  clone      = "ubuntu-cloud"

  cores   = 2
  sockets = 1
  memory  = 2048

  searchdomain = "foo.bar"
  nameserver   = "172.16.1.254"
  ipconfig0    = "ip=172.16.1.${count.index + 111}/24,gw=172.16.1.254"
}

This makes the provider unusable unfortunately...

martin-carpenter commented 2 years ago

I have also had this issue. My fix was to remove the media = line for disk as although in the documentation the value of media can be 'disk' or 'cdrom', this is not valid and working.

NoMoosey commented 2 years ago

Problem solved, see here: #414

"I had the same problem. I connect to a proxmox in my local network using a self-signed certificate, so I had to add the provider setting pm_tls_insecure = true"

This worked for me!

devopstales commented 1 year ago

For me the Pool.Allocate privilege was needed to list the pools. I didn't used any pool but now it is working.

fredrikscode commented 1 year ago

This is still an issue. I'm currently seeing it after having it work fine for months.

GodAtum360 commented 1 year ago

Same here. It usually happens if I am creating 5 or more VMs. Creating 3 works fine.

NazarILdarovich commented 9 months ago

same here (proxmox 8.1.3) Error: Plugin did not respond │ │ with module.k8s[1].proxmox_vm_qemu.cloudinit, │ on modules/proxmox/resource.tf line 1, in resource "proxmox_vm_qemu" "cloudinit": │ 1: resource "proxmox_vm_qemu" "cloudinit" { │ │ The plugin encountered an error, and failed to respond to the │ plugin.(GRPCProvider).ReadResource call. The plugin logs may contain more │ details. ╵ Stack trace from the terraform-provider-proxmox_v2.9.14 plugin: panic: interface conversion: interface {} is string, not float64 goroutine 113 [running]: github.com/Telmate/proxmox-api-go/proxmox.NewConfigQemuFromApi(0xc00072b088, 0xc00072b088?) github.com/Telmate/proxmox-api-go@v0.0.0-20230319185744-e7cde7198cdf/proxmox/config_qemu.go:584 +0x4605 github.com/Telmate/terraform-provider-proxmox/proxmox._resourceVmQemuRead(0xc00012cb80, {0xb66f60?, 0xc0003390e0}) github.com/Telmate/terraform-provider-proxmox/proxmox/resource_vm_qemu.go:1475 +0x457 github.com/Telmate/terraform-provider-proxmox/proxmox.resourceVmQemuRead(0x0?, {0xb66f60?, 0xc0003390e0?}) github.com/Telmate/terraform-provider-proxmox/proxmox/resource_vm_qemu.go:1446 +0x25 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).read(0xdd7840?, {0xdd7840?, 0xc000830d20?}, 0xd?, {0xb66f60?, 0xc0003390e0?}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.25.0/helper/schema/resource.go:712 +0x178 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).RefreshWithoutUpgrade(0xc0003cc7e0, {0xdd7840, 0xc000830d20}, 0xc0000a1790, {0xb66f60, 0xc0003390e0}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.25.0/helper/schema/resource.go:1015 +0x585 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(GRPCProviderServer).ReadResource(0xc000456b70, {0xdd7840?, 0xc000830c00?}, 0xc0005da2c0) github.com/hashicorp/terraform-plugin-sdk/v2@v2.25.0/helper/schema/grpc_provider.go:613 +0x4a5 github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(server).ReadResource(0xc0001323c0, {0xdd7840?, 0xc000830240?}, 0xc000114d20) github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:748 +0x4b1 github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xc6bc20?, 0xc0001323c0}, {0xdd7840, 0xc000830240}, 0xc0001f00e0, 0x0) github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:349 +0x170 google.golang.org/grpc.(Server).processUnaryRPC(0xc000470000, {0xddb420, 0xc0003161a0}, 0xc00088eea0, 0xc00046cdb0, 0x128f770, 0x0) google.golang.org/grpc@v1.53.0/server.go:1336 +0xd23 google.golang.org/grpc.(Server).handleStream(0xc000470000, {0xddb420, 0xc0003161a0}, 0xc00088eea0, 0x0) google.golang.org/grpc@v1.53.0/server.go:1704 +0xa2f google.golang.org/grpc.(Server).serveStreams.func1.2() google.golang.org/grpc@v1.53.0/server.go:965 +0x98 created by google.golang.org/grpc.(*Server).serveStreams.func1 google.golang.org/grpc@v1.53.0/server.go:963 +0x28a Error: The terraform-provider-proxmox_v2.9.14 plugin crashed! This is always indicative of a bug within the plugin. It would be immensely helpful if you could report the crash with the plugin's maintainers so that it can be fixed. The output above should help diagnose the issue.

Cyb3rDudu commented 8 months ago

Same here i tested v2.9.10 from which the log is but for latest i get the same crash

Stack trace from the terraform-provider-proxmox_v2.9.10 plugin:

panic: interface conversion: interface {} is string, not float64

goroutine 145 [running]:
github.com/Telmate/proxmox-api-go/proxmox.NewConfigQemuFromApi(0xc0002cca10, 0xc00069a4b0)
        github.com/Telmate/proxmox-api-go@v0.0.0-20220427175411-e25c3463f0db/proxmox/config_qemu.go:569 +0x46a5
github.com/Telmate/terraform-provider-proxmox/proxmox.resourceVmQemuCreate(0xc0005dc800, {0xae93c0, 0xc00022ee10})
        github.com/Telmate/terraform-provider-proxmox/proxmox/resource_vm_qemu.go:855 +0x24fd
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xd1df00, {0xd1df00, 0xc00057e7e0}, 0xd, {0xae93c0, 0xc00022ee10})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.14.0/helper/schema/resource.go:695 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0003e8700, {0xd1df00, 0xc00057e7e0}, 0xc0000ae340, 0xc0005dc680, {0xae93c0, 0xc00022ee10})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.14.0/helper/schema/resource.go:837 +0xc29
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000151128, {0xd1de58, 0xc0005b2e00}, 0xc000454280)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.14.0/helper/schema/grpc_provider.go:1021 +0xe3c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc00017e320, {0xd1df00, 0xc0004526c0}, 0xc00046c1c0)
        github.com/hashicorp/terraform-plugin-go@v0.9.0/tfprotov5/tf5server/server.go:812 +0x56b
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xbe2c80, 0xc00017e320}, {0xd1df00, 0xc0004526c0}, 0xc0000986c0, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.9.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000144700, {0xd2b6c0, 0xc000484340}, 0xc000294000, 0xc00023ad20, 0x120cfa0, 0x0)
        google.golang.org/grpc@v1.46.0/server.go:1283 +0xcf2
google.golang.org/grpc.(*Server).handleStream(0xc000144700, {0xd2b6c0, 0xc000484340}, 0xc000294000, 0x0)
        google.golang.org/grpc@v1.46.0/server.go:1620 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.46.0/server.go:922 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.46.0/server.go:920 +0x294

Error: The terraform-provider-proxmox_v2.9.10 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
itlinux commented 8 months ago

I got the same problem.

Stack trace from the terraform-provider-proxmox_v2.9.14 plugin:

panic: interface conversion: interface {} is string, not float64

goroutine 74 [running]: github.com/Telmate/proxmox-api-go/proxmox.NewConfigQemuFromApi(0x140005926e0, 0x10271eab6?) github.com/Telmate/proxmox-api-go@v0.0.0-20230319185744-e7cde7198cdf/proxmox/config_qemu.go:584 +0x3b34 github.com/Telmate/terraform-provider-proxmox/proxmox.resourceVmQemuCreate(0x1400026c000, {0x102899ee0?, 0x1400018c460}) github.com/Telmate/terraform-provider-proxmox/proxmox/resource_vm_qemu.go:972 +0x21cc github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).create(0x1029d69a0?, {0x1029d69a0?, 0x14000485980?}, 0xd?, {0x102899ee0?, 0x1400018c460?}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.25.0/helper/schema/resource.go:695 +0x134 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).Apply(0x14000274ee0, {0x1029d69a0, 0x14000485980}, 0x140001495f0, 0x1400011df00, {0x102899ee0, 0x1400018c460}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.25.0/helper/schema/resource.go:837 +0x86c github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(GRPCProviderServer).ApplyResourceChange(0x14000477f50, {0x1029d69a0?, 0x14000485860?}, 0x140001d82d0) github.com/hashicorp/terraform-plugin-sdk/v2@v2.25.0/helper/schema/grpc_provider.go:1021 +0xb70 github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(server).ApplyResourceChange(0x140003bc320, {0x1029d69a0?, 0x14000484150?}, 0x14000292150) github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:818 +0x3b8 github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x10299fa60?, 0x140003bc320}, {0x1029d69a0, 0x14000484150}, 0x140002920e0, 0x0) github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170 google.golang.org/grpc.(Server).processUnaryRPC(0x140003421e0, {0x1029da540, 0x14000102820}, 0x140002a8000, 0x14000485710, 0x102e77860, 0x0) google.golang.org/grpc@v1.53.0/server.go:1336 +0xb7c google.golang.org/grpc.(Server).handleStream(0x140003421e0, {0x1029da540, 0x14000102820}, 0x140002a8000, 0x0) google.golang.org/grpc@v1.53.0/server.go:1704 +0x82c google.golang.org/grpc.(Server).serveStreams.func1.2() google.golang.org/grpc@v1.53.0/server.go:965 +0x84 created by google.golang.org/grpc.(Server).serveStreams.func1 google.golang.org/grpc@v1.53.0/server.go:963 +0x290

Error: The terraform-provider-proxmox_v2.9.14 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely helpful if you could report the crash with the plugin's maintainers so that it can be fixed. The output above should help diagnose the issue.