terraformproxmox

How to handle resources of existing VM inside proxmox using Terraform?


I have a question about how to change resources like RAM, number of cores for existing VM on node node-1 using terraform. I referred this example https://github.com/Telmate/terraform-provider-proxmox/blob/master/examples/cloudinit_example.tf, but this will create VM, I need to change and/or handle existing VM resources. Could anyone explan how to do this? Thanks in advance.


Solution

  • please do check documentation before asking question directly. If you didn't find it please cross check it with source code. It's just pretty straight forward. Provide existing name and vmid. Further add resources, network and add what all you really required.

    Example code is here.

     ​provider​ ​"​proxmox​"​ { 
     ​    pm_tls_insecure ​=​ ​true 
     ​    pm_api_url ​=​ ​"​https://proxmox-server01.example.com:8006/api2/json​" 
     ​    pm_password ​=​ ​"​secret​" 
     ​    pm_user ​=​ ​"​terraform-user@pve​" 
     ​    pm_otp ​=​ ​"​" 
     ​} 
      
     ​resource​ ​"​proxmox_vm_qemu​"​ ​"​cloudinit-test​"​ { 
         vmid = <Existing VMID>
     ​    name ​=​ ​"​<Existing Name of VM>"
      
     ​    ​#​ Node name has to be the same name as within the cluster 
     ​    ​#​ this might not include the FQDN 
     ​    target_node ​=​ ​"​proxmox-server02​" 
      
     ​    
     ​    cores ​=​ ​2 
     ​    sockets ​=​ ​1 
     ​    vcpus ​=​ ​0 
     ​    cpu ​=​ ​"​host​" 
     ​    memory ​=​ ​2048 
     ​    scsihw ​=​ ​"​lsi​" 
      
     ​    ​#​ Setup the disk 
     ​    ​disk​ { 
     ​        size ​=​ ​32 
     ​        type ​=​ ​"​virtio​" 
     ​        storage ​=​ ​"​ceph-storage-pool​" 
     ​        storage_type ​=​ ​"​rbd​" 
     ​        iothread ​=​ ​1 
     ​        ssd ​=​ ​1 
     ​        discard ​=​ ​"​on​" 
     ​    } 
      
     ​    ​#​ Setup the network interface and assign a vlan tag: 256 
     ​    ​network​ { 
     ​        model ​=​ ​"​virtio​" 
     ​        bridge ​=​ ​"​vmbr0​" 
     ​    } 
     ​}